UnauthorizedAccessException
很显示是你没有足够的权限。

解决方案 »

  1.   

    你可以参考一下我的代码:ConnectionOptions connection_wmi = new ConnectionOptions();
    connection_wmi.Username = "administrator";
    connection_wmi.Password = "123";
    connection_wmi.Authority = "ntlmdomain:DOMAIN";ManagementScope scope = new ManagementScope("\\\\10.20.18.35\\root\\CIMV2", connection_wmi);
    scope.Connect();ObjectQuery oq = new ObjectQuery(string.Format("SELECT * FROM Win32_Process where ProcessId = {0}", iPid));
    ManagementObjectSearcher query = new ManagementObjectSearcher(_scope, oq);
    foreach (ManagementObject queryObj in query.Get())
       queryObj.InvokeMethod("Terminate", null);
      

  2.   

    我表示和你碰到的问题一样,本地cosole没问题,打成service注册到服务管理器再用就出问题,也是
    UnauthorizedAccessException后来发现,这个是因为打包成服务的时候权限不对,服务的account应该是NetworkService,而不是localSystem