How to close all explorer folders without closing IE windows? 
Author Message
 How to close all explorer folders without closing IE windows?

Hi. I'm trying to write a VBScript to close all open folder/explorer
windows. It works but it also closes all IE windows! Anyone know how
to tell between a folder window and an IE window? :

Dim oShell, oShellWindows, oShellWindowsList()

Set oShell = CreateObject("Shell.Application")
Set oShellWindows = oShell.Windows
ReDim oShellWindowsList(oShellWindows.Count-1)

For i = 0 to UBound(oShellWindowsList)
        Set oShellWindowsList(i) = oShellWindows(i)
Next
For i = 0 to UBound(oShellWindowsList)
        oShellWindowsList(i).Quit
Next

Mike



Thu, 18 Sep 2003 09:14:11 GMT  
 How to close all explorer folders without closing IE windows?
Dim oShell, oShellWindows, oShellWindowsList()

Set oShell = CreateObject("Shell.Application")
Set oShellWindows = oShell.Windows

For Each oWindow in oShell.Windows
  '
  '...Explorer --> IShellFolderViewDual
  '...IExplore --> HTMLDocument
  '
  If TypeName(oWindow.Document) = "IShellFolderViewDual" Then
    oWindow.Quit
  End If
Next

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> Hi. I'm trying to write a vbscript to close all open folder/explorer
> windows. It works but it also closes all IE windows! Anyone know how
> to tell between a folder window and an IE window? :

> Dim oShell, oShellWindows, oShellWindowsList()

> Set oShell = CreateObject("Shell.Application")
> Set oShellWindows = oShell.Windows
> ReDim oShellWindowsList(oShellWindows.Count-1)

> For i = 0 to UBound(oShellWindowsList)
> Set oShellWindowsList(i) = oShellWindows(i)
> Next
> For i = 0 to UBound(oShellWindowsList)
> oShellWindowsList(i).Quit
> Next

> Mike



Thu, 18 Sep 2003 12:36:58 GMT  
 How to close all explorer folders without closing IE windows?
Excellent! Thanks Michael. There's one problem though, it doesn't work
completely. Apparently as windows close the Shell.Windows list
contracts so the indexing gets out of sync. I think you have to save
the Shell.Windows list in an array and use that to close the folders
don't you think? Btw, where did you get the "IShellFolderViewDual"
information? I have MSDN Library (Jan 2000) and it's not in there
anywhere!

Mike



Quote:
>Dim oShell, oShellWindows, oShellWindowsList()

>Set oShell = CreateObject("Shell.Application")
>Set oShellWindows = oShell.Windows

>For Each oWindow in oShell.Windows
>  '
>  '...Explorer --> IShellFolderViewDual
>  '...IExplore --> HTMLDocument
>  '
>  If TypeName(oWindow.Document) = "IShellFolderViewDual" Then
>    oWindow.Quit
>  End If
>Next

>--
>Michael Harris
>Microsoft.MVP.Scripting
>--

>Please do not email questions - post them to the newsgroup instead.



Thu, 18 Sep 2003 19:01:20 GMT  
 How to close all explorer folders without closing IE windows?
Open a few IE and Explorer windows and run a test script that just displays what TypeName()
returns...

And you're right about removing elements of the ...Windows collection while enumerating it causing
problems.  You had that part right in your 1st post ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> Excellent! Thanks Michael. There's one problem though, it doesn't work
> completely. Apparently as windows close the Shell.Windows list
> contracts so the indexing gets out of sync. I think you have to save
> the Shell.Windows list in an array and use that to close the folders
> don't you think? Btw, where did you get the "IShellFolderViewDual"
> information? I have MSDN Library (Jan 2000) and it's not in there
> anywhere!

> Mike



> >Dim oShell, oShellWindows, oShellWindowsList()

> >Set oShell = CreateObject("Shell.Application")
> >Set oShellWindows = oShell.Windows

> >For Each oWindow in oShell.Windows
> >  '
> >  '...Explorer --> IShellFolderViewDual
> >  '...IExplore --> HTMLDocument
> >  '
> >  If TypeName(oWindow.Document) = "IShellFolderViewDual" Then
> >    oWindow.Quit
> >  End If
> >Next

> >--
> >Michael Harris
> >Microsoft.MVP.Scripting
> >--

> >Please do not email questions - post them to the newsgroup instead.



Fri, 19 Sep 2003 06:03:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Close IE 5 without prompt for close window confirmation

2. Need to close IE window without additional prompt

3. Closing windows without warning in IE 5.5

4. Closing a Windows Explorer Window

5. Closing a Windows Explorer Window

6. Problems Closing a New Window using window.close()

7. windows open and close problem between IE 4.0 and IE 5.0/5.5

8. Stopping an explorer window from closing

9. Trap click on X-button (to close window) in Internet Explorer

10. Closing a child window when parent closes

11. Close all child windows when parent is closed

12. How can I close a window without the destroyer

 

 
Powered by phpBB® Forum Software