Solved

Remote MSI Installation using VB.net

Posted on 2011-09-21
5
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 24

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 24

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

626 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