2

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
BigBrother
  • 1,100
  • 1
  • 9
  • 17

2 Answers2

2

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.

Nimesh Madhavan
  • 6,290
  • 6
  • 44
  • 55
  • Yep, 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? (Editing the question to reflect this). – BigBrother Jun 11 '10 at 06:12
  • Nims - thank you for the information. I've followed the instructions and I can manually execute the manifest application (mt.exe) to create the .exe with embedded manifest. However, using a post-build step doesn't work. I've modified it even based on comments in the page - any ideas? It always errors with "...exited with code 3." – BigBrother Jun 11 '10 at 17:46
  • error 3 is "The system cannot find the path specified." see if giving the absolute path to mt.exe solves the issue. There is a sttackoverflow question on this error here: http://stackoverflow.com/questions/2505612/the-command-bin-mt-exe-nologo-manifest-exited-with-error-code-3-in-ccn – Nimesh Madhavan Jun 12 '10 at 05:47