Installing MSI in remote machine using WMI  
Author Message
udooz





PostPosted: Visual C# General, Installing MSI in remote machine using WMI Top

Hi,

Scope:

I've developed an application which install a MSI package on remote machine. For this, i used WMI. This application was developed on .NET 2.0.

Problem:

I'm not able to install MSI. I met one of the following error.

Details:

Consider the following case:

Machine A: The application is running.

Machine B: where the MSI file (eg: TestAppSetup.MSI) is placed.

Machine C: target machine on which i need to install TestAppSetup.MSI

A, B & C - Running Win2003 Server with WMI Installer Provider.

S.No

Scenario

Test Result

Return Value

1

Running application in A.

MSI file in B. [Accessing this in UNC file path format]

Target machine is A itself with local credential.

PASS

0

2

Running application in A.

MSI file in B.[Accessing this in UNC file path format]

Target machine is C with admin credential.

FAIL

1619

3

Running application in A.

MSI file in C. [Accessing this in UNC file path format]

Target machine is C with admin credential.

PASS

0

But my application exactly needs the scenario #2 only.

I've used the following code which was taken from http://www.hide-link.com/ ;SiteID=1&mode=1&PageID=0.

Please help me asap.

Thanks in advance.

Regards,

Udooz.

Sample Code:

// set these values to your requirements

_DOMAIN = "your.domain"; // your domain name

_MACHINE = "target.machine"; // machine to install on

_USERNAME ="username"; // username of account that exists on A and B

_PASSWORD = "password"; // password for _USERNAME account

_MSI = "\\path\to\package.msi"; // UNC path to the MSI package

_ARGS = "property=value"; // commandline arguments for installer

//

ConnectionOptions co =

new ConnectionOptions();

co.Authority = "kerberos:" + _MACHINE;

co.Username = _USERNAME;

co.Password = _PASSWORD;

//to impersonate current logged user

co.Impersonation = ImpersonationLevel.Delegate;

//PRC_C_IMP_LEVEL_DELEGATE (c++)

co.Authentication = AuthenticationLevel.PacketPrivacy;

co.EnablePrivileges = true;

//define the WMI root name space

ManagementScope ms =

new ManagementScope + _MACHINE + "." , co);

//define path for the WMI class

ManagementPath mp =

new ManagementPath("Win32_Product");

//define new instance

ManagementClass mc =

new ManagementClass(ms, mp, null);

// Obtain input parameters for the method

ManagementBaseObject inParams = mc.GetMethodParameters("Install");

// Add the input parameters.

inParams["AllUsers"] = true; //to install for all users

inParams["PackageLocation"] = _MSI; //msi source file

inParams["Options"] = _ARGS; //'property=setting'

// Execute the method and obtain the return values.

ManagementBaseObject outParams =

mc.InvokeMethod("Install", inParams, null);



Visual C#19  
 
 
RonakPPatel





PostPosted: Visual C# General, Installing MSI in remote machine using WMI Top

I am using your code to do Remote Installation. But i am getting the following error.

Access denied. (Exception from HRESULT: 0x80070005 (E_ACCESSEDDENIED)

at this Location

ManagementBaseObject inParams = mc.GetMethodParameters("Install");


any idea why i am getting this error.



 
 
guy kolbis





PostPosted: Visual C# General, Installing MSI in remote machine using WMI Top

Hi,

In .NET the CLR hosts the CAS (code access security).

If you will try to execute from a share location, you will get a security exception.

Visit my blog for more info about it.

search for the entry: "Sandboxed Applications Can’t Elevate Their Own Permissions"

Hope this helps,

guy kolbis



 
 
Tekchand





PostPosted: Visual C# General, Installing MSI in remote machine using WMI Top

You need to start some services and some modification in local user policy.

there are some basic configration to avoid such kind of error or access denied:

1. If reading logs from another computer on the network, make sure that the user and password you have supplied for each feed correspond to an administrator account on the target computer. That account MUST have a non-blank password.

2. Check that DCOM is enabled on both the host and the target PC. Check the following registry value on both computers:
Key: HKLM\Software\Microsoft\OLE, value: EnableDCOM, should be set to 'Y'

3. Check that WMI is installed. WMI is present by default in all flavors of Windows 2000 and later operating systems, but must be installed manually on NT4 systems.

To check for the presence of WMI, type "wbemtest" into the Run box (Start Menu). If the WMI Tester application starts up, then WMI is present, if not, it must be installed. Consult the Troubleshooting section of the Help for details.

4. Ensure that WMI permissions have been set correctly. Please consult the Troubleshooting section of the Help for details.

5. On a Windows XP Pro computer, make sure that remote logons are not being coerced to the GUEST account (aka "ForceGuest", which is enabled by default computers that are not attached to a domain). To do this, open the Local Security Policy editor (e.g. by typing 'secpol.msc' into the Run box, without quotes). Expand the "Local Policies" node and select "Security Options". Now scroll down to the setting titled "Network access: Sharing and security model for local accounts". If this is set to "Guest only", change it to "Classic" and restart your computer.

6. Also on an XP computer running SP2, configure the firewall to allow remote administration. To do this, open a command prompt and type: netsh firewall set service RemoteAdmin

7. If you have other internal firewalls on your network, you may have to configure them to allow WMI messages. Again, you'll find advice on how to do this in the troubleshooting section of the Help.

Even if you are not knowingly running any firewall software, bear in mind that big-name antivirus solutions such as those produced by McAfee and Symantec often contain their own firewall functionality. If such software is not properly configured to allow WMI traffic, then this may be the cause of the problem.

8. Make sure that no remote access or WMI-related services have been disabled. On an XP machine, the following services should be running (or at least allowed to start on demand):

COM+ Event System
Remote Access Auto Connection Manager
Remote Access Connection Manager
Remote Procedure Call (RPC)
Remote Procedure Call (RPC) Locator
Remote Registry
Server
Windows Management Instrumentation
Windows Management Instrumentation Driver Extensions
WMI Performance Adapter
Workstation