- 1 “Access to the registry key ‘Global’ is denied” when accessing performance counters
- 2 How to Take Full Permissions Control to Edit Protected Registry Keys
- 3 How Do I Know the Registry Key is Protected?
- 4 Take Ownership of a Protected Key in the Registry
- 5 Get Full Control Permissions to a Registry key
- 6 Remove Permissions from a Registry Key
- 7 You Can Change Any Registry Key, But Be Careful
- 8 access to the registry key is denied When i want update the value
- 9 2 Answers 2
- 10 Executable
- 11 Inside Visual Studio
- 12 Application manifest
“Access to the registry key ‘Global’ is denied” when accessing performance counters
I’m attempting to read some performance counters from my ASP.NET application. When I do, I get the error «Access to the registry key ‘Global’ is denied.»
I have tried following the instructions here and here, using the user IIS AppPool\DefaultAppPool , which is the identity my app pool is configured to use:
I have added that user to the Performance Monitor Users group:
And after adding the user, I restarted my computer. But I am still getting the error.
I have also tried adding the users IUSR and NETWORK SERVICE to the Performance Monitor Users group, but those don’t work either. Out of desperation, I tried adding the user «Everyone» to the Performance Monitor Users group, and that actually does work. But my goal is to log statistics from my application in production, and I don’t want to add «Everyone» to that group on the production server.
What else needs to happen in order to read the performance counters without generating a security exception?
How to Take Full Permissions Control to Edit Protected Registry Keys
Learn how to take ownership of protected registry keys in Windows so you can edit them.
The Windows registry is a hassle to edit under normal circumstances, but sometimes you’ll encounter keys that are protected by the system. When you try to add or edit a protected registry key or import settings from a .reg file into a protected key, you’ll run into a few different errors. They say you lack permissions for making changes. However, since it is just a permissions issue, we can get around this by granting your user account in Windows the correct permissions. Read on to learn how.
How Do I Know the Registry Key is Protected?
When trying to create a new entry within a protected key you’ll an error like this:
When you try to edit a protected key, you’ll see an error like this:
When you run a ready-made .reg file to add, change, or delete a protected key, you’ll see an error like this:
Take Ownership of a Protected Key in the Registry
If you encounter the above errors, without a doubt, you’ve encountered a protected registry key. Normally these keys are only open to modification by the Windows system. But if you follow the steps below, you’ll be able to edit any registry key. Be careful with your new power, though.
The Registry Editor is a powerful tool that can render your system unstable or even inoperable if misused. This is a fairly simple change and if you follow our instructions, you shouldn’t have any problems. But make sure you back up the Registry and back up your computer before making changes.
You should also make a System Restore point before continuing so, if something goes wrong, you can always roll back.
Press Windows key + R to open the Run dialog box. Then, type: regedit into the Open box and click OK.
If the User Account Control dialog box displays, click Yes to continue. You may not see this dialog box, depending on your User Account Control settings.
Navigate to the registry key you want to take ownership of. You can enter the path to the key in the box just under the menu bar and press Enter to get to the key quickly.
Right-click on the key and select Permissions.
Click Advanced on the Permissions dialog box.
If your user account isn’t the current Owner, click the Change link.
Type your user name in the Enter the object name to select box and then click Check Names.
Your official user name is inserted into the Enter the object name to select box.
Click OK to accept the change.
Your name should display next to Owner.
If the current key has subkeys you want to take ownership of also, check the Replace owner on subcontainers and objects box.
Then, click Apply. Don’t close the dialog box yet.
After you change the owner of a registry key, you must change the key’s permissions before you can modify it. The next section describes how to do this.
Get Full Control Permissions to a Registry key
If the current key inherited permissions from its parent key, you’ll see a Disable inheritance button.
You must disable inheritance to remove any existing restrictions, so click the Disable inheritance button if it’s there.
To give yourself permission to edit the currently selected registry key, click Add.
On the Permission Entry dialog box, click the Select a principal link.
Then, type your user name in the Enter the object name to select box and click Check Names, like you did earlier.
Then, click OK.
Check the Full Control box under Basic permissions and click OK.
You’ll see your user name in the Permission entries list with Full Control listed in the Access column.
You can set the permissions for only the selected registry key, or you can set permissions on the subkeys also. To apply the same permissions to the selected registry key and down the keys hierarchy to all the the child subkeys, check the Replace all child object permissions with inheritable permissions from this object box.
Then, click OK.
Your user name is added to the Group or user names box. Click OK to close the Permissions dialog box.
Remove Permissions from a Registry Key
Once you make your change to the registry key, it’s a good idea to remove your permissions for the key.
Right-click on the key again, select Permissions, and select your user name in the Group or user names list on the Permissions dialog box.
Then, click Remove. Your user name is removed from the Group or user names list.
If you think you might have to adjust your permissions for this registry key again, you can uncheck the Full Control box under Allow in the Permissions box instead of removing your user name completely. Then, you can just return to the Permissions dialog box for the registry key and check the Full Control box under Allow again for your user name.
You Can Change Any Registry Key, But Be Careful
You should now be able to edit any of the entries within the registry key that you just modified permissions for. Don’t forget that if you want to maintain proper security protocol, after finishing you can go back in and remove your user name from the list of names with full control on the Permissions dialog box. And be very careful when you change anything in the registry.
access to the registry key is denied When i want update the value
i want edit Registry key called «usbstor» value and this my code in update method
and path=»HKEY_LOCAL_MACHINE\system\currentControlset\services\usbstor» keyname=»start» When i run the code i’ll get «Access to the registry key ‘HKEY_LOCAL_MACHINE\system\currentControlset\services\usbstor’ is denied» what is probelm?
2 Answers 2
HKEY_LOCAL_MACHINE is always protected space in registry, so you need to either elavate privilliges to those of at least Power User or run your executable As Administrator (the one built from your solution, should be in ./bin folder) or disable UAC . Either way it will be troublesome inside Visual Studio as long as you don’t have either way configured/set.
Note that if you try to use Run.. -> regedit you are also prompted by UAC, so that’s not only restriction for your app but for access to registry per se.
Inside Visual Studio
Elevating Visual Studio before opening to Run as administrator is sufficent to edit registry from code.
For future usage you might want to create app.manifest and set your application to always require administrator privileges. Right click on your project in Solution Explorer , then: Add -> New Item. -> Application Manifest File . Inside your newly created application manifest, change the line:
From now on it will always prompt UAC if not run as administrator. If you run Visual Studio as not administrator, it will attempt to restart IDE as administrator, prompting to do so before proceeding.