WMI 访问被拒绝

WMI Access Denied

我创建了一个只有一个任务要完成的小应用程序。它是为了获取远程计算机的信息。它适用于发布和调试模式非常好。当我在“.net core”项目中使用它时,应用程序给出 "Access denied" 错误。

到目前为止我发现了什么。 如果 cmd.exe 运行 作为 SYSTEM,应用程序会给出 "Access denied" 错误,但在用户模式下,它可以工作。

如何在 SYSTEM 模式下使用 WMI?我做错了什么?

ConnectionOptions options = new ConnectionOptions
{
   Impersonation = ImpersonationLevel.Impersonate,
   Authentication = AuthenticationLevel.PacketIntegrity,
   EnablePrivileges = true,
   SecurePassword = the_secure_password_of_remote_computer,
   Username = the_username_of_remote_computer
};

var scope = new ManagementScope(@"\" + the_ip_address_of_remote_computer + 
                                        @"\root\cimv2", options);
try
{
   scope.Connect();
   if (scope.IsConnected)
   {
      return true;
   }
   else
   {
      false;
   }
} catch(Exception exception)
{
   // I got the exception here.
   Console.WriteLine("Exception|{0}", exception.Message);
   return false;
}

我使用编组来解决这个问题。

此处:http://rzander.azurewebsites.net/create-a-process-as-loggedon-user/