问题
I couldn't find the ".NET CLR Memory" counter category programmatically (in c#), as in this question. Running as admin solved the issue.
But why do I need to do this? Is there an alternative? I want readonly access, to see GC generation collections inside my app for profiling purposes. Preferably without having to run the app with admin privileges.
Edit:
- I can see the Memory performance counters in the Performance Monitor tool, without running as Admin
- Without running as Admin, I can get a shortened (but not empty) list of performance counter categories programmatically, but this doesn't include the one I'm interested in.
- Our corporate setup is a bit crazy: I have admin privileges, but am not a member of the local admins group. I do have the privileges to add myself, but every 30 minutes or so some automated process removes me. Don't know if this affects anything
- Adding myself to the Performance Monitor Users group had no effect (unless I need to reboot first)
回答1:
You only need to be in group Performance Monitor Users. Simply adding your non admin user to that group should fix the problem.
回答2:
Performance counters are a security hazard. One of the common attack techniques is to observe the execution of secured code. A very common mistake in such code is it not having constant execution time, taking inappropriate shortcuts when a password is invalid for example. This can greatly reduce the number of brute force attack attempts.
In spirit, it will certainly look like you want to bypass your company's security policy. Be wary of mistrusting sys admins, they tend to take this seriously and won't hesitate to report violations. It is certainly best to talk to one of them instead of trying to hack around it. You could look at Perfmon.exe's security demands with SysInternals' Process Explorer. I see a mandatory demand for the built-in "Performance Log Users" group, sounds relevant.
来源:https://stackoverflow.com/questions/20174542/why-do-i-need-to-be-admin-to-read-net-clr-memory-performance-counters