If you use performance counters in web based apps you may end up running into this problem,
[UnauthorizedAccessException: Access to the registry key ‘Global’ is denied.]
UPDATE For IIS7 on windows server 2008 (see the end of this post)
The solution is pretty simple, originally posted here
How to Read Performance Counters Without Administrator Privileges [Ryan Byington]
If you have ever tried to read performance counter data on a Windows 2003 machine as a non admin user you will have likely seen an exception like the following:
System.UnauthorizedAccessException: Access to the registry key ‘Global’ is denied.
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item)
Windows 2003, Windows XP x64 Edition, and Vista require that the user be part of the Performance Monitor Users group to read performance counter data. Simply adding your non admin user to this group will fix this problem.
Accessing counters remotely is another story though. On Windows 2003, Windows XP x64 Edition, and Vista you still must be part of the Performance Monitor Users group on the remote machine but there is a problem with the PerformanceCounter class where it tries to read some registry keys on the remote machine that a non admin users do not have access to. To give your user read access to these keys without having to be an admin on the remote machine complete the following steps on the remote machine:
Open the Registry Editor by going to the Start Menu and selecting Run…, then type “regedit”, and click the OK button.
Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg registry key.
Right click on the “winreg” key and select Permissions. Add users or groups to which you want to grant Read access.
Exit Registry Editor and restart Windows.
For more explanation on this process see here
UPDATE For IIS7 on windows server 2008 (16/11/2011)
This I can’t believe but none the less this is the way it is for IIS7. when you have performed the above steps and you are still receiving the error
Access to the registry key ‘Global’ is denied.
What you need to do is add the App Pool that your web app is running in to the “Performance Monitor Users” group as well. One immediate point is that you cannot find the group within the advanced search when adding objects to the group. You will have to manually type the name of the App Pool following this format
IIS APPPool\DefaultAppPool
Seems ridiculous I know and I haven’t fully got to the bottom of why but I suspect it is most likely something to do with the structure of IIS7 from an NT authentication perspective.
This also now puts an additional rule that one must not rename the App Pool and one must also be vigilant in as much as if you add another web app, creating a new app pool you might need to add this app pool to the group as well.
This updated solution came from here