How to access registry key in a UWP app?

Solution 1:

If your app is a pure UWP app, this is not possible. UWP apps were built with the goal of being lightweight and avoid registry as much as possible, so your app cannot access the registry at all (although some registry keys are created by the system when the app is installed, like URI protocol registration, etc.).

If you really needed to access the registry and don't need to publish your app on Microsoft Store, you could implement a Brokered Windows Runtime Component. This allows you to call on full-trust .NET Framework libraries from UWP which in turn can access the registry. However, app using Brokered Components will not pass certification.

Finally, if your app is a UWP Desktop Bridge app, you have access to the registry - see documentation.

Solution 2:

You can read registry values from a Win32 runFullTrust background process launched from a UWP application, and you can write values in the HKEY_LOCAL_MACHINE hive from an "elevated" Win32 application launched from that runFullTrust process.

These techniques are powerful and using them in a UWP app deployed from the Windows Store requires special scrutiny and permission from Microsoft. The techniques are used by OEMs, but not exclusively restricted to them. If you have a good reason and are able to explain it, you're likely to get approval.

I have written a sample and article that shows exactly how to do this, and you may find it here.