.NET Performance Counters and Security

by mheydt 16. July 2006 01:30 >
I was upgrading software for a client today so that it wouldperiodically take a snapshot of the CPU utilization so that we couldmonitor the workload.  With some google based research, I came up withthe following code to return the cpu utilization:

private static PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");


Unfortunately,when I deployed this to the servers (it runs as a service), the servicewould not start.  Puzzled for a while I took a look at the event logand found the following error:

Servicecannot be started. System.TypeInitializationException: The typeinitializer for 'TNSMI.ArchiveServer.WatcherServiceImpl' threw anexception. ---> System.UnauthorizedAccessException: Access to theregistry 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)
   at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
   at System.Diagnostics.PerformanceCounter.Initialize()
   at System.Diagnostics.PerformanceCounter.....


Turnsout the service is running under a limited account that did not havepermissions to access the performance counters.  The solution after alittle trying was to make the user account a member of the "PerformanceMonitor Users" group.

Technorati Tags: ,

Tags:

.Net | Performance | Security

about the author

I'm a .NET, XAML, and iOS polyglot that loves playing with new things and making cool and innovative stuff.  I am also a Mac junkie.

I am Principal Technologist for SunGard Global Services in NYC, in their Advanced Technologies practice, and I work extensively with SunGard's energy and financial customers.

Note the the posting on this blog are my own and do not represent the position, strategies or opinions of SGS.

twitter

I can't stop thinking big!
Sunday 1:08AM via WindowsLive
Just watched Moneyball. That's my pick for best movie this year.
Saturday 3:51PM via WindowsLive
@vincebelpiede: Report: Skype For Windows Phone Beta Imminent http://t.co/KYNjgg1L#mhtnd
Wednesday 8:39AM via Twitter for Mac
@mashable: Kinect Fusion Will Turn Gaming (and More) Into a 3D Fun House - http://t.co/Ihrq2fY2#mhtnd
Wednesday 8:39AM via Twitter for Mac
New Kinect SDK: http://t.co/57MvA5L5 #mhtnd
Wednesday 8:39AM via Twitter for Mac
Follow me on Twitter

recent comments

None

month list