Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access registry key in a UWP app?

I would like to access windows10 registry key by a UWP app. key as: \HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyName\MyName I can not find any function call to accomplish it. Please indicate me How to do it? Thank you,

like image 488
Yong-Long Liu Avatar asked Dec 05 '22 12:12

Yong-Long Liu


2 Answers

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.

like image 94
Martin Zikmund Avatar answered Jan 16 '23 13:01

Martin Zikmund


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.

like image 45
Paula Avatar answered Jan 16 '23 15:01

Paula