none
Powershell script in hidden window: Start-Process -Wait is not waiting RRS feed

  • General discussion

  • I am using a Powershell script to launch an application, which in this case includes applying some settings before the application runs, then cleaning up once it exist.  I don't want the Powershell window to be visible the whole time the app is running, so I'm launching it in a hidden window.

    Inside the script, I use Start-Process to launch the application, and I use the -Wait parameter so that the script won't continue until the application exist.  But the script is not waiting for the app; it just continues on.  I have verified that -Wait works if the window is not hidden.

    In the TechNet refernce page for the Start-Process command, it says that the -Wait parameter "suppresses the command prompt or retains the window until the process completes."  Since there is no window in this case, I suspect this may be the cause.

    There's a simple workaround - I use the -Passthru parameter with Start-Process, capture the process in a variable, and test the variables's .HasExited property every 12 seconds.

    Thanks,

    Graham


    Tuesday, July 8, 2014 2:02 PM

All replies

  • Did you have a question?

    -- Bill Stewart [Bill_Stewart]

    Tuesday, July 8, 2014 2:21 PM
    Moderator
  • Note that you cannot wait on an installer even if you grab the staring process.  It will exit after launching the installer.  The startup app is just a bootstrap that launches the MSI.


    ¯\_(ツ)_/¯

    Tuesday, July 8, 2014 2:44 PM
  • Yes - is this the expected behavior, or is this an error?
    Tuesday, July 8, 2014 2:51 PM
  • Is what expected behavior? Remember, we don't know what program you're running; we only have the information you have posted in your question and we can't see your screen.

    Post a test case that others here can reproduce. Whittle down your code to only the minimum needed to reproduce the problem.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, July 8, 2014 3:06 PM
    Moderator
  • Yes - is this the expected behavior, or is this an error?

    If you are talking about an installer then yes, this is the expected behavior.

    The installer is a service that runs under system.

    See: Get-Service msiserver

    Note that the exe of MSI you execute just call the installer service and returns.  The exe exits immediately. If you want to know what is happening you can monitor the logs.


    ¯\_(ツ)_/¯

    Tuesday, July 8, 2014 3:35 PM