Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Remote MSI install using c# and WMI

$
0
0

Hi,

I having a problem  whilst trying to install an application on remote machines using WMI. The code im using seems right, but it just isn't working. Can anybody,please, help point me in the right direction? Or maybe post a link/script i can have a look at?

Just to note the strings..

_DOMAIN
_USERNAME
_PASSWORD
_MSIPATH
_ARGS
_MACHINE

are all set correctly before they are passed to the method...

Here is the code I'm working on...The thing is it doesn't throw any Exceptions at all, but it dosen't work either.

So i am at a bit of a loss as how to fix it...

Any help at all would be greatly appreciated.

CODE:
-----

public void installMsi(string _DOMAIN, string _USERNAME, etc, etc)

{
            ManagementScope ms = null;

            // Connection options
            ConnectionOptions co = new ConnectionOptions();
            co.Impersonation = ImpersonationLevel.Impersonate;
            co.Authentication = AuthenticationLevel.PacketPrivacy;
            co.Authority = "ntlmdomain:" + _DOMAIN;

            // local machine
            if (_MACHINE.ToUpper() == Environment.MachineName.ToUpper())
            {
                ms = new ManagementScope(@"\ROOT\CIMV2", co);
            }
            // remote machine
            else
            {
                co.Username = _USERNAME;
                co.Password = _PASSWORD;
                ms = new ManagementScope(@"\\" + _MACHINE + "\root\cimv2", co);
                ms.Options.Impersonation = ImpersonationLevel.Impersonate;
            }
            try
            {
                ms.Connect();
                ManagementPath mp = new ManagementPath("Win32_Product");
                ObjectGetOptions ogo = new ObjectGetOptions();
                ManagementClass mc = new ManagementClass(ms, mp, ogo);
                ManagementBaseObject inParams = mc.GetMethodParameters("Install");
                inParams["PackageLocation"] = _MSIPATH; 
                inParams["Options"] = _ARGS;
                inParams["AllUsers"] = true;
                ManagementBaseObject retVal = mc.InvokeMethod("Install", inParams, null);
            }

            catch (Exception ex)
            {

                MessageBox.Show("Exception: " + ex.Message);

            }
            catch (ManagementException err)
            {
                MessageBox.Show("WMI Error: " + err.Message);
            }
            catch (System.UnauthorizedAccessException unauthorizedErr)
            {
                MessageBox.Show("Connection error: " + unauthorizedErr.Message);
            }

}

//END

 

Thanks.

Fraser


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>