Reputation: 11745
By default : Registry has been disabled So i get "registry editing has been disabled by your administrator" In my application i want to let users access registry when the app runs and deny when app stops. Looking forward for your advice on this.
Upvotes: 0
Views: 3867
Reputation: 15344
Use assembly attribute RegistryPermissionAttribute()
above namespace
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CURRENT_USER")]
//SecurityAction is enum having different security parameters
Upvotes: 0
Reputation: 2790
I'm pretty sure that your admin has disabled access to Regedit.exe using the "Prevent access to registry editing tools" group policy setting — that's why you're getting that "Registry editing has been disabled by your administrator" message.
That does not affect access to the registry, though. Your application can still access and modify the registry (well, at least HKCU) using the RegistryKey class, for instance.
Upvotes: 0
Reputation: 3228
To allow users to edit some registry settings that are normally not accessible, you need to use impersonation. I.e. you need to have your application run as a different user, one with more priviledges.
The easiest way to achieve this it to write a .net Windows Service that runs with higher priviledges. This service can still control what registry settings are allowed to change. So your users start your Winforms app which communicates with your Service to do the actual changes in the registry.
This does require the user (or operations) to install the service on the machine with admin rights.
Upvotes: 1
Reputation: 9519
I am guessing that your app runs on Vista or Win7 and you don't have access to HKEY_LOCAL_MACHINE. In order to edit registry values in that area you need to add a manifest in your project and add this line to it:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Upvotes: 0