问题
I'm trying to see if it's possible to read the registry from a Windows 8 app. I can usually use Registry.GetValue() but I don't have that option when creating the Win 8 app. Doing some digging shows that the Registry.GetValue() belongs to the Microsoft.Win32 namespace which isn't available in the Win 8 app references properties tab.
I did some googling but I couldn't find any concrete evidence that you cannot read the registry. I fear that I won't be able to do this because of sandboxing Win 8 apps.
回答1:
If you really need to, you can do that by using interop services.
So import the WinAPI functions you need (you can get the signatures from PInvoke.net):
[DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
public static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey,
uint ulOptions, int samDesired, out UIntPtr phkResult);
And make your own wrapper around them.
But as far as I know, that's not allowed and your app won't pass the certification.
来源:https://stackoverflow.com/questions/17050394/read-the-registry-using-win-8-app