Forum Discussion

SNDHe's avatar
SNDHe
Copper Contributor
Mar 31, 2022

Installing multiple MSI's

I am attempting to install two MSI's using Start process. One completes and writes to the log and the other is not starting. What am I missing?

 

 

Start-Process msiexec.exe -ArgumentList '/i "C:\Utilities\Program 15.msi" /qr /promptrestart  /lv c:\Utilities\Logs\Program.log' -Wait
Start-Process msiexec.exe -ArgumentList '/i "C:\Utilities\Program2.msi" /qr /promptrestart /lv c:\Utilities\Logs\Program2.log'

 

 

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    SNDHe 

     

    You're missing the "-Wait" on the second command line.

     

    It's common for applications/processes/services to release control in a non-blocking manner to the calling process but if that calling process exits, the underlying processes it initiated are also closed.

     

    For such processes, you need to wait for the called process (in this case msiexec.exe) to signal back to the caller (Start-Process) that it's actually finished doing what it had to do.

     

    Without the -Wait on the second command line, msiexec.exe:

     

    1. Gets started by the Start-Process call;
    2. Releases control back to Start-Process so it can do other things if it wants to;
    3. Start-Process interprets that as msiexec has actually finished it's work;
    4. Start-Process exits causing the child msiexec process to close and nothing gets done as a result.

     

    Cheers,

    Lain

    • Leavii's avatar
      Leavii
      Brass Contributor

      LainRobertson 

       

      Just want to get a full understanding of what you mean, as mine works the way the OP provided.  Granted I wouldn't do it this way, but while we are on the subject lol. 

       

      Doing it this way both of my executables started.  I may be missing a detail, but sounds like you are saying it doesn't or shouldn't work with msiexec.exe?

       

      Start-Process msiexec.exe -argumentlist '-i "C:\Users\%username%\Desktop\VNC Server 6.4.1 x64.msi" /qr /promptrestart /lv "C:Test.log" ' -wait
      Start-Process msiexec.exe -ArgumentList '-i "C:\Users\%username%\Desktop\VNC Viewer 6.19.325 x64.msi" /qr /promptrestart /lv "C:Test.log"'
      pause

       

       

      Thanks!

      • LainRobertson's avatar
        LainRobertson
        Silver Contributor

        Leavii 

         

        Wait is a directive to the hosting process to actively poll the process it created and not exit until the child process has indicated it has exited.

         

        Not using the wait method results in the calling process starting the new process and exiting immediately. This is why cmd.exe has the "/c" parameter, the "start" command has the "/wait" parameter and Start-Process has the "-Wait" parameter, to name some examples.

         

        Using .NET as the reference point, this equates to the functionality described in the WaitForExitAsync() method (usually - there's variations.)

         

        Calling from an ongoing process such as a console shell often works where calling from inside other hosts like the task scheduler environment or even the "Run" box within the Windows Start menu can yield early which results in processes terminating early. Which is why they supply some form of "wait" option as a means for receiving such a directive.

         

        So, it's not a one-size-fits all answer since it depends on your starting point but my guess is that those commands are executing in something other than a persistent shell. I'm basing that on the statement that first command leverages the "wait" and works while the second does not.

         

        Process.WaitForExitAsync(CancellationToken) Method (System.Diagnostics) | Microsoft Docs

         

        The .NET reference is just for further reading if you're interested. The concept is old and has nothing to do with .NET.

         

        Cheers,

        Lain

  • Leavii's avatar
    Leavii
    Brass Contributor

    SNDHe 

     

    Hello,

     

    Not sure here.  I can start msiexec.exe installations back-to-back via powershell. Possibly the application you are attempting to install? 

     

    Please include any errors, or troubleshooting steps you have tried.  Also, how are you executing the script?  

Resources