Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perXautomatik/e708e177dabd688c931f3d2e76ff6c7d to your computer and use it in GitHub Desktop.
Save perXautomatik/e708e177dabd688c931f3d2e76ff6c7d to your computer and use it in GitHub Desktop.
powershell - How to Correctly Check if a Process is running and Stop it - Stack Overflow
# get Firefox process
$firefox = Get-Process firefox -ErrorAction SilentlyContinue
if ($firefox) {
# try gracefully first
$firefox.CloseMainWindow()
# kill after five seconds
Sleep 5
if (!$firefox.HasExited) {
$firefox | Stop-Process -Force
}
}
Remove-Variable firefox
#Url: https://stackoverflow.com/questions/28481811/how-to-correctly-check-if-a-process-is-running-and-stop-it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment