C# WMI Eventwatcher 代码在 Windows 7 上停止工作,出现安全异常
该代码在 Windows XP 上运行良好多年。用户不是本地管理员。
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace");
ConnectionOptions co = new ConnectionOptions();
co.EnablePrivileges = true;
ManagementEventWatcher watcher = new ManagementEventWatcher(new ManagementScope(@"root\cimv2",co), query);
watcher.EventArrived += StopEventArrived;
watcher.Start();
这会在 Windows 7 上引发 SecurityException,以非管理员身份运行时访问被拒绝。在 XP 上,无需管理员即可正常工作。
在此链接 MS指出“Windows 7:低完整性用户对本地 WMI 操作具有只读权限。”。我想这就是问题所在。
但我找不到任何关于如何改变这一点的线索。
This is code that worked fine on Windows XP for years. User is not local administrator.
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace");
ConnectionOptions co = new ConnectionOptions();
co.EnablePrivileges = true;
ManagementEventWatcher watcher = new ManagementEventWatcher(new ManagementScope(@"root\cimv2",co), query);
watcher.EventArrived += StopEventArrived;
watcher.Start();
This throws an SecurityException on Windows 7, Access Denied when running as a non admin. On XP this works fine without being admin.
On this link MS states that 'Windows 7: Low-integrity users have read-only permissions for local WMI operations.'. I guess this is the problem.
But I can't find any clue on how to change this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法:
我最终创建了一个在“本地系统”上下文中运行的 Windows 服务,并通过 WCF 命令该服务。
Workaround:
I ended up creating a windows service that runs in 'local system' context, and commanding this service by WCF.