Created
July 3, 2014 02:36
-
-
Save NigelThorne/aac1ec706b3e170885ee to your computer and use it in GitHub Desktop.
Powershell script to kill IE when it hangs (used in automation testing)
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
@powershell -NoProfile -ExecutionPolicy unrestricted .\Kill_IE_WhenHung.ps1 |
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
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 | |
} |
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"
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
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.