My case happens when I run $IE.quit() already, but internet explorer still exists in the task manager.
- if I run the quit function at "quit IE 1" there, the Internet Explorer will close/end (not exits in Task Manager),
- but when I run it at "quit IE 2" there, the IE not end (still exist in Task Manager)
- if run with
$IE.Visible = $true
it has no such problem. - Environment: Windows Server 2016, PowerShell v5.1
- May I know what may cause this?
- May I know after the "confirm page loaded", what happened to
$IE
? And possibly cause IE not to quit. - Or how I can trace this kind of problem?
I do try to run this without try
/catch
, but the same thing happens. I try to put $IE = null
, but the same, while, the $IE.Quit()
description as to force the end of IE, suppose no wonder what is running on the IE. It will end the task.
Here is the PowerShell script:
$looping = 10
timenowhms = (Get-Date -f HH:mm:ss)
try {
$Url = "http://localhost:8080/commandcenter/checking.aspx"
$IE = New-Object -Com InternetExplorer.Application
$IE.Height = 700
$IE.Width = 750
$IE.Top = 10
$IE.Left = 10
$IE.Visible = $false; # can turn on for testing purpose
$IE.Navigate2($url);
$IEPID = [IntPtr]::Zero
[Win32Api]::GetWindowThreadProcessId($IE.HWND, [ref]$IEPID);
# quit IE 1
$IE.Quit();
} catch {
$timenowhms = (Get-Date -f HH:mm:ss);
echo "$td_date $timenowhms Open website failed";
if ((Get-Process -Name "iexplore*" | ? {$_.Id -eq $IEPID} | measure).Count -eq 1) {
Stop-Process -Id $IEPID -force
};
exit 1
}
# confirm page loaded
while ($ie.Busy -eq $true) {
if ($looping -eq 0) {
$timenowhms = (Get-Date -f HH:mm:ss);
echo "$td_date $timenowhms Timeout, page not show";
if ((Get-Process -Name "iexplore*" | ? {$_.Id -eq $IEPID} | measure).Count -eq 1) {
Stop-Process -Id $IEPID -Force
};
exit 1
} else {
Start-Sleep -Milliseconds 2500;
$looping--;
}
}
# quit IE 2
# $IE.Quit();
exit