Last active
January 30, 2023 09:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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