Solved

install msi file on remote machine using vb.net code

Posted on 2009-05-06
8
5,440 Views
Last Modified: 2013-11-14
I want to run an msi installation file on remote servers from a vb.net application on my machine. I can directly access these machines using the path: \\servername\ and I have administrative rights. Attached is the code I'm trying to use. First, I copy the msi unto the remote server which works but the code to execute the msi doesn't work. I'm using the process.start() method to start the windows msiexec program but it doesn't seem to work. What am I doing wrong?

Also, how can I check if the installation was successfull via my vb.net application and write to a log file.

Thanks

San
Private Sub Myfunc()
 
        Dim fi As System.IO.FileInfo = Nothing
 
        Dim fileWithServerNames As String = System.Environment.CurrentDirectory & "\ListOfServers.txt"
        Dim sr As StreamReader = New StreamReader(fileWithServerNames)
 
        Dim tempServerPath As String = ""
        Dim myMSIFilePath As String = ""
        Dim myMSIFileName As String = ""
 
        'Get the msi file from local machine
        Dim mylocalFilePath As String() = Directory.GetFiles(System.Environment.CurrentDirectory & MSI_FOLDER)
        myMSIFilePath = mylocalFilePath(0)
        myMSIFileName = getFileName(myLocalFilePath(0))
 
 
        Try
            Do While sr.Peek() >= 0
 
                tempServerPath = "\\" & sr.ReadLine() & TEMP_PATH
 
                If Directory.Exists(tempServerPath) Then
 
                    'First copy the MSI file to the remote server
                    File.Copy(myMSIFilePath, tempServerPath & "\" & myMSIFileName, True)
                    If File.Exists(tempServerPath & "\" & myMSIFileName) Then
                        writeToLog("==MSI copied to " & tempServerPath)
 
                        'Next, install the msi on the server
                        Dim procinfo As ProcessStartInfo = New ProcessStartInfo()
                        procinfo.FileName = "msiexec.exe"
                        procinfo.Arguments = "/q /i " & tempServerPath & "\" & myMSIFileName
 
                        Dim proc As New System.Diagnostics.Process
                        proc = System.Diagnostics.Process.Start(procinfo)
 
                        'Wait for the installation to finish
                        proc.WaitForExit()
 
                        'Code to check if the installation successful???
                        '?
                    Else
                        writeToLog("==MSI copy failed to " & tempServerPath)
                    End If
 
                    writeToLog(" ")
 
                Else
                    writeToLog(tempServerPath & "==folder does not exist")
                End If
 
            Loop
            sr.Close()
 
        Catch ex As Exception
            writeToLog(tempServerPath & "==>file read failed" & vbLf & ex.Message)
        End Try
 
    End Sub

Open in new window

0
Comment
Question by:Sanmarie
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24324575
1. what credentials has the process on the remote machine? you don't specify any. Can you start there  something simple, for example cmd.exe, using this code?

2. Maybe it's because msiexec on remote machine is supposed to find the msi file on the same share that you are using.

3. I would use Process Monitor on remote machine.
0
 

Author Comment

by:Sanmarie
ID: 24324963
1. What credentials? YOu mean if it has execute rights? Yes, since I'm accessing as administrator. I'll try the cmd.exe and get back to you

2. Well I copied it to C:\temp on the remote machine and tried to run it from there

3. ?

Bear with me if I don't understand the basics. I just know vb.net and we want to install the msi on all the servers next week and I want to run a script instead of logging on to each machine and installing.

Thanks

San
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24325405
1. when msiexec is launched on the remote machine, it runs as some user. Which one?

2. Not so. On the remote machine you run is as
procinfo.Arguments = "/q /i " & tempServerPath & "\" & myMSIFileName

i.e. msiexec on remote machine receives the path of the msi file in the share.

3. http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

finally,

> we want to install the msi on all the servers

if this is windows network, the best way to achieve this is by publishing your installation in the active directory, making it available to those servers.
0
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.

 

Author Comment

by:Sanmarie
ID: 24326260
Okay. Sorry for the delayed response but I was trying a few things. I added the following credentials to the code so it would use my administrative credentials: (See the attached code)

The thing is, it's launching the msiexec program on my local machine. As you can tell, I don't know what I'm doing.

I'll try your other suggestions as a last resort but I saw vb6 code online that was able to do this so I think vb.net should be able to do it too. I'll try some more and if it doesn't work then I'll have to use AD or your recommended microsoft link.

Thanks

San



procinfo.UseShellExecute = False
        procinfo.LoadUserProfile = True
        procinfo.UserName = "myUsrname"
        procinfo.Domain = "myDomain"
        procinfo.WorkingDirectory = strDestFolderPath
 
        'Security part
        Dim pwdString As New System.Security.SecureString
        Dim strPassword As String = "myStringPassword"
 
        ' Construct the SecureString password
        For Each c As Char In myStringPassword
            pwdString.AppendChar(c)
        Next
 
        procinfo.Password = pwdString
 
        Dim proc As New System.Diagnostics.Process
        proc = System.Diagnostics.Process.Start(procinfo)
        proc.Start()

Open in new window

0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
ID: 24326849
well, you are absolutely right:

================
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

Process Class

Provides access to local and remote processes and enables you to start and stop local system processes.
================

see http:Q_20659410.html .

Also, isn't it easier to run the installation on each machine from a common centralized share, rather than copy it to each machine?

You can also consider using psexec (google the word) which does exactly this thing, plus is channels stdout output back to you. But the best advise is to set it up by group policy, especially if you do this occasionally.
0
 

Author Comment

by:Sanmarie
ID: 24327586
Right. The Process class is for the LOCAL system as you have said. No wonder it's not working.

I'm writing the code using WMI (Windows Management Information) and I will get back to you.

>>Also, isn't it easier to run the installation on each machine from a common centralized share, rather >>than copy it to each machine?
Hmm, I guess I could connect to each from my local machine and run it instead of copying it to each server first. Is this what you mean? I have access to all the servers from my local machine but I'm not sure I do from a common centralized share. I'd have to go through the network admin group to do that and if I can get the code to work then I won't bother.

Thanks. I'll also look into the psexec later.

I'm learning a lot so far. I will keep you posted once I'm done with the code. Thanks for sticking with me on this.

San
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24329670
> Hmm, I guess I could connect to each from my local machine and run it instead of copying it to each server first. Is this what you mean?

no. This:

1. put the msi file on some server share seen by all servers where you want to deploy it; can even be your own machine, for example \\mymachine\myshare\test.msi

2. then on each server run

msiexec /i \\mymachine\myshare\test.msi

this way, you don't have to copy to each machine, they all take the file from one centralized share.

0
 

Author Comment

by:Sanmarie
ID: 24330766
Cool!
I was able to install the msi on test servers from my test vb.net application using the example from here:
http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/1b3e1c46-b70d-4caf-86fa-45f3b3c0f8a7

I tweaked the example above to suit my needs and it installs perfectly.

>>put the msi file on some server share seen by all servers where you want to deploy it; can even be >>your own machine, for example \\mymachine\myshare\test.msi
Excellent. Now I get what you mean. I will do this

Thank you so much for helping me Vadimrapp1. You deserve all the points

San


0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

822 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