远程安装MSI返回错误1619

时间:2019-06-19 08:56:46

标签: c# installation wmi

如果程序包在网络驱动器或共享文件夹上的位置,则远程安装msi返回错误1619。如果程序包位于远程计算机上,则说明安装成功。

static void Main(string[] args)
        {
            string[] app = { "1.msi", "2.msi", "3.msi" };
            string retVal = "";

            ConnectionOptions options = new ConnectionOptions();
            string targetIpAddress = "targetPC";   // you can change this target IP address
            options.Username = @"domain\username";
            options.Password = "password";
            ManagementScope scope = new ManagementScope(("\\\\" + targetIpAddress + "\\root\\cimv2"), options);
            scope.Connect();

            ManagementPath p = new ManagementPath("Win32_Product");
            ManagementClass classInstance = new ManagementClass(scope, p, null);
            ManagementBaseObject inParams = classInstance.GetMethodParameters("Install");
            ManagementBaseObject outParams;
            inParams["AllUsers"] = true;
            inParams["Options"] = string.Empty;

            foreach (var item in app)
            {
                inParams["PackageLocation"] = @"\\network_drive\app_location" + item;
                outParams = classInstance.InvokeMethod("Install", inParams, null);
                retVal = outParams["ReturnValue"].ToString();

                retVal_install(app, inParams, retVal, item);
            }

            Console.ReadKey();

        }

        public static void retVal_install(string[] _app, ManagementBaseObject _inParams, string _retVal, string _item)
        {
            switch (_retVal)
            {
                case "0":

                    Console.WriteLine("The installation " + _item + " completed successfully.");

                    break;

                case "1619":

                    Console.WriteLine("This installation package \n\r\n\r " + _inParams["PackageLocation"] + "\n\r\n\rcould not be opened, please verify that it is accessible.");

                    break;

                    Console.WriteLine("This installation package \n\r\n\r " + _inParams["PackageLocation"] + "\n\r\n\rcould not be opened, please verify that it is a valid MSI package.");

                    break;

                default:
                    Console.WriteLine(_retVal);
                    break;
            }
        }
    }

远程安装必须返回值0(安装成功完成。)

0 个答案:

没有答案