简体   繁体   English

使用 WMI 调用解决“拒绝访问”异常

[英]Addressing “Access Denied” Exception with WMI Calls

I'm getting an exception with a message of "Access Denied" when executing against a WMI request.在针对 WMI 请求执行时,我收到一条带有“拒绝访问”消息的异常。 Some WMI requests appear to require higher security privileges than others.某些 WMI 请求似乎比其他请求需要更高的安全权限。 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.不管是否有更好的方法,它现在都成为使这种 WMI 方法起作用的仇杀。

I've attempted the code at Security Tools -> WMI Programming Using C#.Net and still receive the exception.我已经在Security Tools -> WMI Programming Using C#.Net 中尝试了代码,但仍然收到异常。 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?如何允许我的代码执行这些 WMI 请求?

I'm running on Windows 7 Pro and VS 2010 in a new C# command line project.我在一个新的 C# 命令行项目中运行 Windows 7 Pro 和 VS 2010。

Edit: Choosing "Run As Administrator" for the VS2010 instance and then executing the code works.编辑:为 VS2010 实例选择“以管理员身份运行”,然后执行代码即可。 How do I automate this so a user doesn't have to manually elevate the privilege?如何自动执行此操作,以便用户不必手动提升权限?

Some of these WMI calls may need admin privileges.其中一些 WMI 调用可能需要管理员权限。 did you try right clicking your .exe file and selecting "Run As Administrator"?您是否尝试过右键单击 .exe 文件并选择“以管理员身份运行”?

Add a manifest to your program so that it always runs with Admin privileges.向您的程序添加清单,以便它始终以管理员权限运行。 Here is another link which is more to the point. 是另一个更重要的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM