Last active
June 22, 2017 05:42
-
-
Save tdewin/5e40803df29faba3c5c4d8b63d55347f to your computer and use it in GitHub Desktop.
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
$apps = @('viber','skype','lync','outlook','spotify') | |
$forceclose = @() | |
$procs = get-process | |
foreach($kp in $apps) { | |
$procs | ? { $_.name -imatch $kp } | % { | |
$proc = $_ | |
$result = $proc.CloseMainWindow() | |
if ($result -eq $false) { | |
$forceclose += $proc | |
} | |
} | |
} | |
if($forceclose.count -gt 0) { | |
start-sleep -Seconds 2 | |
$forceclose | % { | |
$_ | Stop-Process -Force -PassThru | |
} | |
} | |
start-sleep -Second 2 | |
$procs = get-process | |
foreach($kp in $apps) { | |
$procs | ? { $_.name -imatch $kp } | Stop-Process -force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment