我想在远程计算机上安装 MSI 包。本地和远程计算机都是名为“adn.lan”的域的成员,并且我作为参数传递给连接的用户/密码对远程计算机具有完全访问权限。当我将connection.Authority设置 为“ntdlmdomain:adran.lan”时,返回参数显示“无效参数”,当我将其保留为null
并使其成为备注时,connect()
将成功连接,但当它尝试安装包时,返回参数显示寻址的包是不可访问的。
这是我尝试过的代码。
ConnectionOptions connection = new ConnectionOptions();
//connection.Authority = "ntdlmdomain:adn.lan"; // "kerberos:" + domain + @"\" + machine;
connection.Username = username;
connection.Password = password;
//connection.Impersonation = ImpersonationLevel.Identify ;
connection.Authentication = AuthenticationLevel.Packet;
ManagementScope scope = new ManagementScope("\\\\RemoteMachineName\\root\\CIMV2", connection);
scope.Connect();
ManagementPath p = new ManagementPath("Win32_Product");
ManagementClass classInstance = new ManagementClass(scope, p, null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Install");
inParams["AllUsers"] = true;
inParams["Options"] = string.Empty;
inParams["PackageLocation"] = "\\\\LocalMachineName\\Share\\Prescription.msi";
ManagementBaseObject outParams = classInstance.InvokeMethod("Install", inParams, null);
string retVal = outParams["ReturnValue"].ToString();
当我设置theconnection.Impersonation
为身份时,结果将是“拒绝访问”。