我想在遠程計算機上安裝MSI軟件包。 本地和遠程計算機都是域名「adn.lan」 的成員,並且我作爲連接參數傳遞的用戶/密碼具有對遠程計算機的完全訪問權限。 當我設置connection.Authority到「ntdlmdomain:adran.lan」返回參數顯示「無效參數」當我離開它,因爲null
並使其爲說,在connect()
將連接成功,但是當它試圖安裝包的返回參數顯示被解決的包是不可訪問的。由WMI進行遠程安裝的問題:遠程計算機無法訪問安裝軟件包
這是我試過的代碼。
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
到身份的結果將是「訪問被拒絕」。
現在我決定將MSI軟件包複製到遠程機器,然後從本地解決文件路徑以解決問題但我仍然對獲得更好的解決方案感興趣。 – 2011-05-24 07:59:58