Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remote MSI Installation using VB.net

Posted on 2011-09-21
5
Medium Priority
?
709 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 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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