not_a_generic_user
not_a_generic_user

Reputation: 2178

Start multiple programs using Powershell without leaving the window open afterward

I want to load a series of programs and then have the PowerShell instance close afterward. This is what I have:

Start-Process -FilePath <path to chrome>
Start-Process -FilePath <path to firefox>
Start-Process -FilePath <path to vs code>

So basically, I want to run it like a batch file where it launches the listed programs and then goes away. But instead, it leaves the powershell window open and if I manually close it, VScode shuts too (the browsers stay open for some reason).

I see there's a -wait option for start-process, but I want the opposite: -nowait. Just open and go away. How can I do this? The other commands like invoke and startjob don't seem right.

Upvotes: 0

Views: 2749

Answers (1)

codewario
codewario

Reputation: 21408

Since these are GUI applications, you don't need to worry about using
Start-Process -Wait:$False; GUI applications don't block in PowerShell (or Command Prompt) by default. You can simply run those programs with the call-operator & (technically optional to use the call-operator but it covers the path-with-spaces case):

& "\path\to\guiprogram.exe"

If you need to do this with a non-GUI application, then you would need to use
Start-Process -Wait:$False (or omit -Wait altogether since Start-Process doesn't block by default) to continue executing:

Start-Process -Wait:$False "\path\to\program.exe"
Start-Process "\path\to\program.exe"

-SwitchParameter:$Value syntax allows you to set the explicit value of [switch] parameters. Usually the switch parameter is implicitly managed. It is in an "on (true)" state if provided, and an "off (false)" state when omitted.

However, you can explicitly set the value of a switch parameter by suffixing the parameter with :$Value. The value's truthiness will be evaluated and the switch state will match "on" for $True and "off" for $False.

Upvotes: 1

Related Questions