Addressing “Access Denied” Exception with WMI Call

2019-05-25 08:32发布

问题:

I'm getting an exception with a message of "Access Denied" when executing against a WMI request. Some WMI requests appear to require higher security privileges than others. Ultimately my goal is to monitor process launches within the system and log. Regardless if there is a better approach, its now become a vendetta in getting this WMI approach to work.

I've attempted the code at Security Tools -> WMI Programming Using C#.Net and still receive the exception. If you copy the code found in the blog entry you can reproduce my issue.

Another post on a similar topic can be found at link text but again, try the code and you'll the see the same security exception.

How do I permit my code to execute these WMI requests?

I'm running on Windows 7 Pro and VS 2010 in a new C# command line project.

Edit: Choosing "Run As Administrator" for the VS2010 instance and then executing the code works. How do I automate this so a user doesn't have to manually elevate the privilege?

回答1:

Some of these WMI calls may need admin privileges. did you try right clicking your .exe file and selecting "Run As Administrator"?

Add a manifest to your program so that it always runs with Admin privileges. Here is another link which is more to the point.



回答2:

http://social.technet.microsoft.com/Forums/en/winserverhyperv/thread/2a7e8ba9-2a9e-46c2-8233-3eb65cfd16cc

This will help u..