Solved

Remote MSI Installation using VB.net

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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