Skip to content

Instantly share code, notes, and snippets.

@NigelThorne
Created July 3, 2014 02:36
Show Gist options
  • Save NigelThorne/aac1ec706b3e170885ee to your computer and use it in GitHub Desktop.
Save NigelThorne/aac1ec706b3e170885ee to your computer and use it in GitHub Desktop.
Powershell script to kill IE when it hangs (used in automation testing)
@powershell -NoProfile -ExecutionPolicy unrestricted .\Kill_IE_WhenHung.ps1
while (1) {
if ( $allProcesses = get-process -name iexplore -errorAction SilentlyContinue ) {
foreach ($oneProcess in $allProcesses) {
if ( -not ($oneProcess.MainWindowHandle -and $oneProcess.Responding) ) {
write "Status = Not Responding: Kill& Restart.."
$oneProcess.kill()
}
}
}
if ( $allProcesses = get-process -name werfault*,wermgr* -errorAction SilentlyContinue ) {
foreach ($oneProcess in $allProcesses) {
write "Killing Werfault or WerMgr"
$oneProcess.kill()
}
}
start-sleep 5
}
@NigelThorne
Copy link
Author

Loops for ever looking for Internet Explorer in a hung state and killing it. WerFault and WerMgr are processes that show dialogs saying IE died.

@NigelThorne
Copy link
Author

An alternative to these scripts may be something based on http://www.maketecheasier.com/kill-non-responsive-programs-in-windows/

 taskkill /F /FI "STATUS eq NOT RESPONDING"

@NigelThorne
Copy link
Author

Note: My inspiration came from http://powershell.com/cs/forums/t/7002.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment