Solved

Remote MSI Installation using VB.net

Posted on 2011-09-21
5
577 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now