thefallguy
asked on
using Shell.Application to close all IE windows
I wrote a vbscript that closes Internet explorer windows. The main reason i'm doing it this way it to get the LocationURL property of the objIE object before I call Quit on it.
The problem is that not all windows close this way if you have around 5 open Internet Explorer Windows.
Any suggestions?
Set objShell = CreateObject("Shell.Applic ation")
Set objShellWindows = objShell.Windows
dim i, nCount
nCount = objShellWindows.Count
nCount = nCount - 1
for i = 0 to nCount
dim objIE
set objIE = objShellWindows.Item(i)
if (not objIE is nothing) then
'Do objIE.LocationURL related stuff here
objIE.Quit
end if
next
The problem is that not all windows close this way if you have around 5 open Internet Explorer Windows.
Any suggestions?
Set objShell = CreateObject("Shell.Applic
Set objShellWindows = objShell.Windows
dim i, nCount
nCount = objShellWindows.Count
nCount = nCount - 1
for i = 0 to nCount
dim objIE
set objIE = objShellWindows.Item(i)
if (not objIE is nothing) then
'Do objIE.LocationURL related stuff here
objIE.Quit
end if
next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
for anyone looking for a solution... working code.
Dim objInternetExplorerShell
Dim objInternetExplorerShellWi ndows
Dim internetExplorerWin
Set objInternetExplorerShell = CreateObject("Shell.Applic ation")
Set objInternetExplorerShellWi ndows = objInternetExplorerShell.W indows
Do Until objInternetExplorerShell.W indows.Cou nt = 0
For Each internetExplorerWin In objInternetExplorerShellWi ndows
On Error Resume Next
'Grab LocationURL info here and write it wherever you'd like.
'Text1.Text = Text1.Text & " " & internetExplorerWin.Locati onURL & vbNewLine
If Err Then
Err.Clear
End If
internetExplorerWin.Quit
Set internetExplorerWin = Nothing
Next
If objInternetExplorerShell.W indows.Cou nt = 0 Then Exit do
Loop
Set objInternetExplorerShellWi ndows = Nothing
Set objInternetExplorerShell = Nothing
Dim objInternetExplorerShell
Dim objInternetExplorerShellWi
Dim internetExplorerWin
Set objInternetExplorerShell = CreateObject("Shell.Applic
Set objInternetExplorerShellWi
Do Until objInternetExplorerShell.W
For Each internetExplorerWin In objInternetExplorerShellWi
On Error Resume Next
'Grab LocationURL info here and write it wherever you'd like.
'Text1.Text = Text1.Text & " " & internetExplorerWin.Locati
If Err Then
Err.Clear
End If
internetExplorerWin.Quit
Set internetExplorerWin = Nothing
Next
If objInternetExplorerShell.W
Loop
Set objInternetExplorerShellWi
Set objInternetExplorerShell = Nothing
For i = nCount to 0 step -1
I would presume that if a windows shuts itself down completely, the ShellWindows Object will refresh.
If this is the case, then once you have Item 0 quit, The next item will take it's place. So if the windows shut down fast enough, you will only see half of them go away.