views:

391

answers:

1

I'm attempting to write a key to Registry. It works on Windows XP, but fails on Windows 7 / Vista.

The code below throws a Security Exception with description "Requested registry access is not allowed."

RegistryKey regKey = 
    Registry.LocalMachine.OpenSubKey("SOFTWARE\\App_Name\\" + subKey, true);

I realise that this has to do with the UAC settings, but I couldn't figure out an ideal workaround.

I don't want to fork out another process, and may be don't even want to request for any credentials. Just want it to work the same way as on Windows XP. I have modified the manifest file and removed requestedExecutionLevel node. This seems to do the trick.

Is there any other possible workaround, and are there any serious flaws with the "manifest" solution?

+1  A: 

You do not have permissions to write to global key for the whole machine. Can you store your data under Current user key? That should not need administrator permissions.

Giorgi
I realise that too. I wanted that all the users on the current machine be able to read/write this registry entry.
Trainee4Life
In that case the application has to run as administrator.
Giorgi
see http://stackoverflow.com/questions/562350/requested-registry-access-is-not-allowed
M. Jahedbozorgan