Win32_Service射击管理异常(访问被拒绝)

时间:2013-07-04 06:53:44

标签: asp.net wmi

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() 

2 个答案:

答案 0 :(得分:1)

尝试设置或添加dword

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system\LocalAccountTokenFilterPolicy = 1

在要连接的计算机上。在我的情况下,它甚至没有重新启动。

答案 1 :(得分:0)

通过添加ManagementScopeConnectionOptions类来尝试以下操作:

 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"]); 
 }

有关ConnectionOptions class

的更多信息