Every decent OS in 2023 should provide a method for this.
Yes, that's rather the problem—there isn't just one way to do that, which makes it a portability issue.