Solved

Remote MSI Installation using VB.net

Posted on 2011-09-21
5
601 Views
Last Modified: 2012-05-12
I have a vb.net app that searches for specific computers on the network based on criteria from a database and applies modifications if needed.  In certain cases it needs to install an msi.  I experimented with WMIC using:

/node:RemoteComputerName product call install true,"" , "C:\Test_Install.msi"

This worked great and allowed me to install the msi using my domain admin credentials regardless if a user is logged into the remote computer or not.  However, when trying to apply the attached vb.net solution, it will only install if the computer is logged in and only if I pass the credentials of the user that is currently logged in. The error log on the remote computer will show the failure as an MSIINSTALLER issue related to user rights.

I am not opposed to using something other than WMI but absolutely want to automatically initiate the remote install from my vb.net application.  I do not want to visit any solution that requires Group Policy deployment or SCCM.

This solution is applied to workstations running XP and WIN 7, both 32 and 64 bit.
 
Imports System.Management

Public Class Form1

    Private Sub subWMInstall()

        Dim strComputer As String = "RemoteComputerName"
        Dim ConnectionOptions As New System.Management.ConnectionOptions
        ConnectionOptions.Username = Trim("DomainAdminUserName") '(strComputer & "\LocalAdminUserName") for local user account
        ConnectionOptions.Password = Trim("DomainAdminUserPassword")

        Dim ManagementScope As New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", ConnectionOptions)
        Dim ManagementPath As New System.Management.ManagementPath("Win32_Process")
        Dim ManagementOptions As New System.Management.ObjectGetOptions
        Dim ManagementClass As New System.Management.ManagementClass(ManagementScope, ManagementPath, ManagementOptions)
        Dim OutputParameters As System.Management.ManagementBaseObject
        Dim InputParameters As System.Management.ManagementBaseObject

        Try

            ManagementScope.Connect()
            InputParameters = ManagementClass.GetMethodParameters("Create")
            InputParameters("CommandLine") = "msiexec /package C:\Test_Install.msi"
            OutputParameters = ManagementClass.InvokeMethod("Create", InputParameters, Nothing)

        Catch ex As Exception
            MsgBox("There was an error connecting to the remote computer." & vbNewLine & ex.Message)
        End Try

    End Sub
    
End Class

Open in new window

0
Comment
Question by:exproDavidLowery
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Nagendra Pratap Singh
ID: 36579646
Try using the computer account for installation.
0
 

Author Comment

by:exproDavidLowery
ID: 36581500
I do not know how to specify the Machine or System account in this context.  Do you have an example or link to an example?
0
 
LVL 23

Expert Comment

by:Nagendra Pratap Singh
ID: 36582149
I cannot write the code myself as it has been many years that I wrote anything apart from scripts!

Anyway this may help you
http://www.codeproject.com/KB/vista-security/VistaSessions.aspx
0
 

Accepted Solution

by:
exproDavidLowery earned 0 total points
ID: 36717821
The details in that link might eventually lead to fixing the code above but would take a considerable amount of time to absorb, modify, and implement.  Alternatively,  I found a very simple working example in a VBS script that was easily modified to work in VB.net as long as the application is run with a domain admin account:
Private Sub subWMIInstall(strComputer As String)

        Dim errReturn As String

        Try
            Dim objWMIService As Object = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Dim objSoftware As Object = objWMIService.Get("Win32_Product")
            errReturn = objSoftware.Install("c:\Test_Install.msi", , True)

        Catch
            MsgBox("FAILED: " & errReturn)

        End Try


    End Sub

Open in new window

0
 

Author Closing Comment

by:exproDavidLowery
ID: 36902242
Was looking for a simple fix to the provided code or an alternate solution which i found elsewhere but decided to share.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question