ManagementObjectSearcher servSearcher = new ManagementObjectSearcher(theScope, new ObjectQuery("SELECT * FROM Win32_Service"));
foreach (ManagementObject servObj in servSearcher.Get()){
}
Win32_Process
不会触发任何错误,但在尝试访问Win32_Service
时会触发管理异常(拒绝访问)
System.Management.ManagementException: Access denied at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)at
System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
答案 0 :(得分:1)
尝试设置或添加dword
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system\LocalAccountTokenFilterPolicy = 1
在要连接的计算机上。在我的情况下,它甚至没有重新启动。
答案 1 :(得分:0)
通过添加ManagementScope
和ConnectionOptions
类来尝试以下操作:
ConnectionOptions options = new ConnectionOptions();
options.EnablePrivileges = true;
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope("\\\\FullComputerName\\root\\cimv2",options);
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Service");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection) {
Console.WriteLine(m["CheckPoint"]);
}
的更多信息