Dear all,
My application works well on Vista, Win 7 32 and 64 bits.
It modifies some registry key in HKEY_LOCAL_MACHINE.
But when run on Win 8 (both 32 and 64), with minimum level UAC (I drag the slider to bottom, then restart), it doesn't work. And there is the error:
"Application attempted to perform an operation not allowed by the security policy. To grant this application the required permission, contact your system administrator, or use the Microsoft .NET Framework Configuration tool. Requested registry access is not allowed."
When I disable completely UAC of win 8 by editing registry, then restart computer, my application works well.
How can I deal with win 8 UAC enable with c#?
Thank you very much.
C#, Windows 8 UAC, and registry edit
Page 1 of 111 Replies - 507 Views - Last Post: 21 January 2013 - 01:13 PM
Replies To: C#, Windows 8 UAC, and registry edit
#2
Re: C#, Windows 8 UAC, and registry edit
Posted 16 January 2013 - 07:07 AM
Simply - you don't. The UAC is there for a reason and it is doing its job - stopping people from maliciously editing the registry.
#3
Re: C#, Windows 8 UAC, and registry edit
Posted 16 January 2013 - 07:32 AM
What does your application manifest look like for your C# program? It should have <requestExecutionLevel level="requireAdministrator" uiAccess="false" /> somewhere in it if you are touching the local machine hive.
#4
Re: C#, Windows 8 UAC, and registry edit
Posted 16 January 2013 - 07:36 AM
modi123_1, on 16 January 2013 - 07:07 AM, said:
Simply - you don't. The UAC is there for a reason and it is doing its job - stopping people from maliciously editing the registry.
Thanks for you reply.
I will continue to work to find out the way to deal with win 8 UAC. It makes me crazy, why doesn't MS keep UAC works like win 7...
Skydiver, on 16 January 2013 - 07:32 AM, said:
What does your application manifest look like for your C# program? It should have <requestExecutionLevel level="requireAdministrator" uiAccess="false" /> somewhere in it if you are touching the local machine hive.
I tried it, and also tried <requestExecutionLevel level="highestAvailable" uiAccess="false" />
It doesn't work on win 8 with UAC enabled.
#6
Re: C#, Windows 8 UAC, and registry edit
Posted 16 January 2013 - 11:32 PM
If there is equivalent key into HKCU, try to use that instead.
#7
Re: C#, Windows 8 UAC, and registry edit
Posted 17 January 2013 - 07:29 AM
CurrentUser and LocalMachine aren't necessarily interchangeable.
If you have a setting you want to remain the same across all users it would have to go to LocalMachine. For example if a point of sale software was always to open on the second monitor, regardless of which clerk was logged in.
So my question is: What setting are you trying to change? Is it one for your own program or is it a system setting?
You may just have to accept that it is time to stop using the registry for your program's settings. We've done it for decades but as you can see, we're being pushed out of the registry. You might want to start looking at serializing your settings to a SettingsObj class for example. Or using the Application Settings built in to .NET.
Separating data from GUI - PLUS - serializing the data to XML
Easy Application Settings example
If you have a setting you want to remain the same across all users it would have to go to LocalMachine. For example if a point of sale software was always to open on the second monitor, regardless of which clerk was logged in.
So my question is: What setting are you trying to change? Is it one for your own program or is it a system setting?
You may just have to accept that it is time to stop using the registry for your program's settings. We've done it for decades but as you can see, we're being pushed out of the registry. You might want to start looking at serializing your settings to a SettingsObj class for example. Or using the Application Settings built in to .NET.
Separating data from GUI - PLUS - serializing the data to XML
Easy Application Settings example
#8
Re: C#, Windows 8 UAC, and registry edit
Posted 17 January 2013 - 08:18 AM
Additionally, Metro Windows 8 apps are run in an app container with even tighter permissions.
#9
Re: C#, Windows 8 UAC, and registry edit
Posted 17 January 2013 - 06:08 PM
tlhIn`toq, on 17 January 2013 - 07:29 AM, said:
CurrentUser and LocalMachine aren't necessarily interchangeable.
If you have a setting you want to remain the same across all users it would have to go to LocalMachine. For example if a point of sale software was always to open on the second monitor, regardless of which clerk was logged in.
So my question is: What setting are you trying to change? Is it one for your own program or is it a system setting?
You may just have to accept that it is time to stop using the registry for your program's settings. We've done it for decades but as you can see, we're being pushed out of the registry. You might want to start looking at serializing your settings to a SettingsObj class for example. Or using the Application Settings built in to .NET.
Separating data from GUI - PLUS - serializing the data to XML
Easy Application Settings example
If you have a setting you want to remain the same across all users it would have to go to LocalMachine. For example if a point of sale software was always to open on the second monitor, regardless of which clerk was logged in.
So my question is: What setting are you trying to change? Is it one for your own program or is it a system setting?
You may just have to accept that it is time to stop using the registry for your program's settings. We've done it for decades but as you can see, we're being pushed out of the registry. You might want to start looking at serializing your settings to a SettingsObj class for example. Or using the Application Settings built in to .NET.
Separating data from GUI - PLUS - serializing the data to XML
Easy Application Settings example
I try to change my own program setting in registry, and it works well under Vista, Win 7 (UAC enabled). It just has error when running under Win8 (UAC enabled).
Thank you for your suggestion, I'll take a look at serialization.
Additional, this is my code
RegistrySecurity rs = new RegistrySecurity();
RegistryKey rk = Registry.ClassesRoot.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl); // Opens the key again with full control.
rs.SetOwner(new NTAccount("newAdmin"));// Set the securitys owner to newAdmin
rs.SetAccessRuleProtection(true, false);
rk.SetAccessControl(rs);// Set the key with the changed permission so Administrator is now owner.
#10
Re: C#, Windows 8 UAC, and registry edit
Posted 17 January 2013 - 08:19 PM
If you are trying to open local machine, shouldn't it be:
Just worrying. . .
RegistryKey rk = Registry.LocalMachine.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, Registry Rights.FullControl);
Just worrying. . .
#11
Re: C#, Windows 8 UAC, and registry edit
Posted 17 January 2013 - 08:29 PM
b0zhidar, on 17 January 2013 - 08:19 PM, said:
If you are trying to open local machine, shouldn't it be:
Just worrying. . .
RegistryKey rk = Registry.LocalMachine.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, Registry Rights.FullControl);
Just worrying. . .
Unfortunately, i need to modify the permission inside Classes Root
#12
Re: C#, Windows 8 UAC, and registry edit
Posted 21 January 2013 - 01:13 PM
It maybe a lack of imagination on my part, but the only "white hat" need to change the owner of registry hives I can think of is that you are reviving a machine that used to be part of an Active Directory domain and was first installed using a domain account. But for that one time need, you would just change the ACLs using tools that you can get from SysInternals.
Why are you trying to change the owner of a registry hive?
Why are you trying to change the owner of a registry hive?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|