11 Replies - 3430 Views - Last Post: 21 January 2013 - 01:13 PM Rate Topic: -----

#1 activelive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 30-January 12

C#, Windows 8 UAC, and registry edit

Posted 16 January 2013 - 06:47 AM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: C#, Windows 8 UAC, and registry edit

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8842
  • View blog
  • Posts: 33,119
  • Joined: 12-June 08

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.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3418
  • View blog
  • Posts: 10,523
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

#4 activelive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 30-January 12

Re: C#, Windows 8 UAC, and registry edit

Posted 16 January 2013 - 07:36 AM

View Postmodi123_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...

View PostSkydiver, 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.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5416
  • View blog
  • Posts: 11,601
  • Joined: 02-June 10

Re: C#, Windows 8 UAC, and registry edit

Posted 16 January 2013 - 07:37 AM

I think modi123_1 already answered that:

Quote

its job - stopping people from maliciously editing the registry.

So the change was needed to make the registry more secure.
Was This Post Helpful? 0
  • +
  • -

#6 b0zhidar  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 24
  • Joined: 21-December 12

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.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5416
  • View blog
  • Posts: 11,601
  • Joined: 02-June 10

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
Was This Post Helpful? 1
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3418
  • View blog
  • Posts: 10,523
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

#9 activelive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 30-January 12

Re: C#, Windows 8 UAC, and registry edit

Posted 17 January 2013 - 06:08 PM

View PosttlhIn`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

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.

Was This Post Helpful? 0
  • +
  • -

#10 b0zhidar  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 24
  • Joined: 21-December 12

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:
RegistryKey rk = Registry.LocalMachine.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, Registry Rights.FullControl);


Just worrying. . .
Was This Post Helpful? 0
  • +
  • -

#11 activelive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 30-January 12

Re: C#, Windows 8 UAC, and registry edit

Posted 17 January 2013 - 08:29 PM

View Postb0zhidar, on 17 January 2013 - 08:19 PM, said:

If you are trying to open local machine, shouldn't it be:
RegistryKey rk = Registry.LocalMachine.OpenSubKey(subkey, RegistryKeyPermissionCheck.ReadWriteSubTree, Registry Rights.FullControl);


Just worrying. . .

Unfortunately, i need to modify the permission inside Classes Root
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3418
  • View blog
  • Posts: 10,523
  • Joined: 05-May 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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1