SecurityException when accessing performance counters

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top