One thing a lot of developers don’t know is that Microsoft provides a bunch of URI schemes to access Windows-internal features directly (e.g., from within an application). This applies especially to the settings window: Imagine your Windows Store app needs to access the device’s microphone, however the only thing you receive is an exception because the user did not permit microphone access. Of course, you can show a notification explaining why microphone access is necessary – but what if you could open the Windows Settings dialog directly from within the app, and jump to the “Let apps use my microphone” section without a single button click?
Let’s start by having a look at the official list of URIs provided by Microsoft: ms-settings: URI scheme reference
You’ll notice that the list is quite long and covers every corner of the Windows Settings menu, but how are we supposed to use it? Well, since these URIs are registered within Windows, we can “navigate” to them just as we’d do with every web URL. For example, find the URI for opening the Privacy setting’s Microphone section (ms-settings:privacy-microphone
), copy it, paste it into Windows Explorer’s address bar and hit Enter!
While this is cool for testing, to do this from within an App we need to convert is to code. No need to worry, also this one is really straightforward, since we can use the same technique we would for opening any web page from a Store App and do all of it within one line of C# code:
var success = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
Create a URI object from the string, pass it to the UWP framework’s URI launcher, and (if needed) store the result in a variable to see whether the operation was successful!
And the best is: Since (as mentioned before) we are dealing with URIs, this is not limited to UWP apps – we could even open the Settings dialog from a .NET console app, using the process starter:
System.Diagnostics.Process.Start("ms-settings:privacy-microphone");
There is only one thing to remember (and probably to check before running this line of code): For obvious reasons, all these URIs only work in Windows 10 (and, some of them, in Windows 8)!