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
Solved

install msi file on remote machine using vb.net code

Posted on 2009-05-06
8
5,468 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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