Restarting Processes

by Oct 2, 2009

You may want to occasionally restart a single-instance process. However, shutting down a process does not necessarily mean it is killed in that second. You may have to wait for the shutdown process to complete before you can restart the application. In PowerShell v.2, Wait-Process can do just that. The following line will re-launch Notepad once you close it:

Wait-Process notepad -ea SilentlyContinue; notepad

If you'd like to receive some notification once a process has fully shut down, try this:

Wait-Process notepad -ea SilentlyContinue; `a

Note that in V1, you need to add Write-Host:

Wait-Process notepad -ea SilentlyContinue; Write-Host `a

Or even this:

Wait-Process notepad -ea SilentlyContinue; `
(New-Object -COM SAPI.SpVoice).Speak('Ok, the sucker is down!')

Twitter This Tip! ReTweet this Tip!