Reputation: 79
I have following C# code, which reads the UAC state from registry in Windows 7
object obj = Registry.LocalMachine.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA", (long)1);
It works perfectly on Windows 7 with admin/not-admin accounts. It always returns the default value I provide it under Windows 8. The registry key is there. I can see its value with regedit. But the C# code does not read it. Can anybody tell why? It is a .net 4 application. The user account is unelevated admin.
Upvotes: 4
Views: 2933
Reputation: 844
It returns the default value (on both Windows 7 and 8). Here's the code that reads the correct Registry value on both Windows 7 and 8, without running as administrator.
object obj = Registry.GetValue(
@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\",
"EnableLUA",
(long)1);
Note that we call GetValue
method on Registry
, not on Registry.LocalMachine
, and we pass key and value name as two separate parameters.
Upvotes: 5
Reputation: 1
You need to require administrative privileges at least to be able to access the registry by default. Windows 8 developers possibly thinks it's safer to keep it that way.
Upvotes: -1