Sequential Software Installation

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Thom Schumacher Thom Schumacher 10 months, 2 weeks ago.

  • Author
    Posts
  • #34352
    Profile photo of Brandon Lashmet
    Brandon Lashmet
    Participant

    Suppose that one has the following functions:

    function InstallPackage1
    {
    start-process msiexec /i package1.msi /qn
    }
    
    function InstallPackage2
    {
    start-process msiexec /i package2.msi /qn
    }
    

    What's the best way to run these if I want the first package to run first, then have the second package wait for the first to complete before starting? I looked into workflows, but am wondering if there's another way (e.g., InstallPackage1 -wait InstallPackage2...).

    Thanks.

  • #34354
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Hi Brandon,

    You can ue the -Wait parameter with Start-Process for this to occur.

    The only thing you need to watch with this is that the msiexec doesnt launch another process and then quit itself from the installation. It's less likely with msi files though.

  • #34414
    Profile photo of Brandon Lashmet
    Brandon Lashmet
    Participant

    Thanks for the response Tim.

    If I have several functions using the wait parameter, for example:

    
    function InstallPackage1
    {
    start-process msiexec /i package1.msi /qn -wait
    }
    

    Would calling each function one after the other yield the desired result?

    InstallPackage1
    InstallPackage2
    etc.

    Or would it be necessary to combine them all into one function?:

    
    function InstallPackages
    {
    start-process msiexec /i package1.msi /qn -wait
    start-process msiexec /i package2.msi /qn -wait
    }
    

    Thanks again.

  • #34456
    Profile photo of Brandon Lashmet
    Brandon Lashmet
    Participant

    Now that I think about it, calling the functions one after the other or combining them into one should yield the exact same results (since calling the function just executes the code inside).

    I'll test the first method, but I'm curious if workflows would be appropriate here (probably not because some commands require user input).

  • #34484
    Profile photo of Joseph Monarch
    Joseph Monarch
    Participant

    Here is what we use at my company that works very well for different types of installs.

    # Function Get_Running_Process
    ## Get_Running_Process looks for the following running processes:
    ## ~ wscript
    ## ~ cscript
    ## ~ msg
    ## Each time a process is found to be running the error count goes down.
    ## The resulting action is to loop through the running processes until all three are no longer running.
    ## Once wscript and cscript end the script looks for the msg process.  If the msg process is found to be running,
    ## the process is terminated with force to supress the prompt.  Once all errors are clear, script gets any orphaned
    ## msiexec processes and terminates them.
    function Get_Running_Process() {
    	Get-Process wscript -ErrorVariable err -ErrorAction SilentlyContinue
    	Get-Process cscript -ErrorVariable +err -ErrorAction SilentlyContinue 
    	Get-Process msg -ErrorVariable +err -ErrorAction SilentlyContinue
    	do {
    		if($err.count -lt 3) {
    			Get-Process wscript -ErrorVariable err -ErrorAction SilentlyContinue 
    			Get-Process cscript -ErrorVariable +err -ErrorAction SilentlyContinue 
    			Get-Process msg -ErrorVariable +err -ErrorAction SilentlyContinue
    			Get-Process msg -ErrorVariable msg -ErrorAction SilentlyContinue
    			if($msg.count -eq 0) {
    				Stop-Process -ProcessName msg -Force
    			}
    		}
    	}
    	until($err.count -eq 3)
    	$err.Clear()
    	Get-Process msiexec -ErrorVariable err -ErrorAction SilentlyContinue
    	if($err.Count -eq 0) {
    		Stop-Process -processname msiexec -Force
    	}
    	Start-Sleep -Seconds 5
    }
    
    # Redundant but in our environment necessary. 
    $err.Clear()
    Get-Process msiexec -ErrorVariable err -ErrorAction SilentlyContinue
    if($err.Count -eq 0) {
    	Stop-Process -processname msiexec -Force
    }
    
    cscript "\\server\runinst.vbs" | Out-Null
    Get_Running_Process
    
    Start-Process "\\server\install.bat" -Wait | Out-Null
    Get_Running_Process
    
    

    This is the scaled down version. We have about 20 applications that get installed via a form with checkboxes. If the box is checked then the application install with the above parameters.

  • #34489
    Profile photo of Thom Schumacher
    Thom Schumacher
    Participant

    I know that dealing with MSI's is difficult so I chose to get this package off of Githhub to install and check my msi status:

    https://github.com/heaths/psmsi

    I have some sample code that I used to install ARR.. AT the time I wrote this i was using Octopus for continous integration. So you may have to change the scripting a bit. Hopefully this helps in some small way.

    I'll post that code on my github gist account here:

    https://gist.githubusercontent.com/crshnbrn66/2a45a52712dd8190ac73/raw/810d5e535190b945fcf46825e71478b6a9d6ba88/setup-arr.ps1

You must be logged in to reply to this topic.