Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
See more:
Hello Friends,
I am creating Remote MSI installer which would take care of installing msi packages remotely.
I got the source code for the same. Its WMI concept and the code snippet is like below

C#
{
ConnectionOptions connection = new ConnectionOptions(); 
connection.Username = username; 
connection.Password = password; 
connection.Authentication = AuthenticationLevel.Packet; 
ManagementScope scope = new ManagementScope("\\\\RemoteMachineIP\\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"] = "\\\\RemoteMachineIP\\C$\\Sample.msi";//installer is stored at this location
ManagementBaseObject outParams = classInstance.InvokeMethod("Install", inParams, null);   string retVal = outParams["ReturnValue"].ToString(); 
 }


But in above code as soon as control reaches to ManagementBaseObject class and after executing that line it throws an exception "NOT FOUND"


will Anybody help me out of this?....Does anybody know about usage and syntax of managementBaseobject Class?.



Thanks in Advance,
Amit Savant
Posted
Updated 27-Jul-11 1:42am
v2
Comments
DaveAuld 27-Jul-11 7:42am    
Edit: Added code block formatting......

1 solution

Hi,

Try this:
ConnectionOptions connection = new ConnectionOptions();
           //connection.Username = username;
           //connection.Password = password;
           ConnectionOptions options = new ConnectionOptions();
           string targetIpAddress = "210.0.0.000";   // you can change this target IP address
           connection.Authentication = System.Management.AuthenticationLevel.Packet;
           ManagementScope scope = new ManagementScope(("\\\\" + targetIpAddress), options);
           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"] = "\\\\" + targetIpAddress + "\\C$\\Sample.msi";//installer is stored at this location
           ManagementBaseObject outParams = classInstance.InvokeMethod("Install", inParams, null);
           string retVal = outParams["ReturnValue"].ToString();


Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem
 
Share this answer
 
v2
Comments
amitsavant 28-Jul-11 0:42am    
Thanks for your reply Algem.
I tried that way but it throws an exception same as mentioned earleir..
Is it relates to OS type??
I am Installing it on Windows Server Standard Service pack2..i.e. my target machine...

Thanks in Advance,
Amit
Al Moje 28-Jul-11 1:16am    
Hi, I thing so...
cause I try it; and is working with us...
maybe you can modify some security options...
amitsavant 28-Jul-11 5:35am    
Hi Algem,
The code is working fine. The problem was in MSI itself. I tried it with several different msi, It does it's Job :)

Thank you for your help and support,

Regards,
Amit
SujayC 23-Apr-15 4:09am    
Thanks for this solution. Just have a query, does the value of inParams["PackageLocation"] need to be file location at remote computer or it can be local path as well.... Basically i need to install one msi on remote machine but the size of MSI is quite large so I don't want to copy that file over to remote machine can this be achieved by passing local path in inParams["PackageLocation"] property?

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