SecurityException when accessing performance counters

  • Thread starter Thread starter escristian
  • Start date Start date
E

escristian

C# Visual 2005.

I am trying to delete a performance counter category using this call:
PerformanceCounterCategory.Delete, and I get a securityexception if my
user is not an admin, from MSDN documentation it says I need the
PerformanceCounterPermissionAccess.Administer permission. Now can
someone please tell me how to check if I have that permission.

Thanks
 
You can do this:

PerformanceCounterPermission permission = new
PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer,
"machine name", "category name");
permission.Demand();

Of course, this will have the effect of throwing a SecurityException if
you do not have the permission, which you would have to catch and then act
on, which would be the same if you wrapped a try/catch block around the call
to Delete.
 
Back
Top