Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How remotely install msi package with c#. I use this code, but this return code "1603"
C#
ManagementScope scope;

            ConnectionOptions connectionOptions = new ConnectionOptions
            {
                Authentication = AuthenticationLevel.PacketPrivacy,
                Impersonation = ImpersonationLevel.Impersonate
            };


            /*
            connOptions = new ConnectionOptions();
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            connOptions.Username = "DOMAIN" + "\\" + "user";
            connOptions.Password = "password";
             */ 

            scope = new ManagementScope(@"\\" + "KA16500" +
                                          @"\ROOT\CIMV2", connectionOptions);


            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"] = @"\\ka16500\sharePoint\1.msi";

            ManagementBaseObject outParams = classInstance.InvokeMethod("Install", inParams, null);

            string retVal = outParams["ReturnValue"].ToString();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900