Skip to content

Instantly share code, notes, and snippets.

@tdewin
Last active June 22, 2017 05:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdewin/5e40803df29faba3c5c4d8b63d55347f to your computer and use it in GitHub Desktop.
Save tdewin/5e40803df29faba3c5c4d8b63d55347f to your computer and use it in GitHub Desktop.
$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