Navigate to folder in current Windows Explorer instance 
Author Message
 Navigate to folder in current Windows Explorer instance

OK, I know I can open a folder in Windows Explorer like this:

Set oShell = CreateObject("WScript.Shell")
oShell.run("explorer /e, c:\temp")

This however, always opens in a new instance.
How would I go about navigating to c:\temp if windows explorer is already
open?

Thanks,
-Jeremy



Mon, 18 Apr 2005 11:00:05 GMT  
 Navigate to folder in current Windows Explorer instance
If your code is inside the browser at the time you want to do this, then

document.location.href= "c:\temp"


Quote:
> OK, I know I can open a folder in Windows Explorer like this:

> Set oShell = CreateObject("WScript.Shell")
> oShell.run("explorer /e, c:\temp")

> This however, always opens in a new instance.
> How would I go about navigating to c:\temp if windows explorer is already
> open?

> Thanks,
> -Jeremy



Mon, 18 Apr 2005 12:35:36 GMT  
 Navigate to folder in current Windows Explorer instance

Quote:

> OK, I know I can open a folder in Windows Explorer like this:

> Set oShell = CreateObject("WScript.Shell")
> oShell.run("explorer /e, c:\temp")

> This however, always opens in a new instance.
> How would I go about navigating to c:\temp if windows explorer is
> already open?

Here's an HTA example of locating all open Windows Explorer windows and sending them all to "C:\"...

<html>
<head>
<hta:application id='ohta'
    applicationName='Open Windows Explorer Windows'
    border='thick'
    borderstyle='normal'  
    caption='yes'
    maximizebutton='yes'
    minimizebutton='yes'
    showintaskbar='yes'
    singleinstance='yes'
    sysmenu='yes'
    version='1.0'
    windowstate='normal'

<script language='VBScript'>'----- Script --------->
'==== global variables
Option Explicit
  Dim oBody, oShApp

sub window_onload()

  document.title = oHTA.applicationName
  set oBody = document.all.idBody

  with oBody.style
    .fontfamily = "verdana"
    .fontsize = "x-small"
  end with

  set oShApp = CreateObject("shell.application")

  Call RefreshList()

end sub

sub idRefresh_onclick()

  Call RefreshList()

end sub

sub RefreshList()

  dim oWin, oDoc, oFolder
  dim s, n
  Const br = "<br> "
  Const sp = "" '"&nbsp;&nbsp;"

  idOut.innerHTML = ""
  s = ""

  for each oWin in oShApp.windows
    if oWin.locationURL <> "" then
      Select Case typename(oWin.document)
        Case "HTMLDocument"
          ' it's an IE browser window...
        Case "IShellFolderViewDual"
          ' it's a Windows Explorer window
          set oFolder = oWin.document.folder
          s = s & oFolder.self.path & "<br>"
          oWin.Navigate "c:\"
        Case Else
          msgbox typename(oWin.document) & vbcrlf & oWin.locationURL
      end select
    end if
  next

  idOut.innerHTML = s

end sub

</script><!----------------------- End Script ----->
</head>

<body id="idBody"><!-------------- Body ----------->
  <DIV id='idMain'><!------------- UI Area -------->
    <form>
      <button id='idRefresh' style='width:100'>Refresh</button>&nbsp;&nbsp;
      <button id='idClose' style='width:100'
         onclick='javascript:window.close();'>Close</button>
    </form>
    <hr size='1'>
  </DIV>
  <DIV id='idOut'><!------------ Output Area --->
  </DIV>
</body>

</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Wed, 20 Apr 2005 02:27:26 GMT  
 Navigate to folder in current Windows Explorer instance
Micheal,

Thank you very much!

I just had to change IShellFolderViewDual to IShellFolderViewDual2

Using WindowsXP and IE6, if that matters.

-Jeremy

Quote:
>> OK, I know I can open a folder in Windows Explorer like this:

>> Set oShell = CreateObject("WScript.Shell")
>> oShell.run("explorer /e, c:\temp")

>> This however, always opens in a new instance.
>> How would I go about navigating to c:\temp if windows explorer is
>> already open?
> Here's an HTA example of locating all open Windows Explorer windows
> and sending them all to "C:\"...

> <html>
> <head>
> <hta:application id='ohta'
>     applicationName='Open Windows Explorer Windows'
>     border='thick'
>     borderstyle='normal'
>     caption='yes'
>     maximizebutton='yes'
>     minimizebutton='yes'
>     showintaskbar='yes'
>     singleinstance='yes'
>     sysmenu='yes'
>     version='1.0'
>     windowstate='normal'

> <script language='vbscript'>'----- Script --------->
> '==== global variables
> Option Explicit
>   Dim oBody, oShApp

> sub window_onload()

>   document.title = oHTA.applicationName
>   set oBody = document.all.idBody

>   with oBody.style
>     .fontfamily = "verdana"
>     .fontsize = "x-small"
>   end with

>   set oShApp = CreateObject("shell.application")

>   Call RefreshList()

> end sub

> sub idRefresh_onclick()

>   Call RefreshList()

> end sub

> sub RefreshList()

>   dim oWin, oDoc, oFolder
>   dim s, n
>   Const br = "<br> "
>   Const sp = "" '"??"

>   idOut.innerHTML = ""
>   s = ""

>   for each oWin in oShApp.windows
>     if oWin.locationURL <> "" then
>       Select Case typename(oWin.document)
>         Case "HTMLDocument"
>           ' it's an IE browser window...
>         Case "IShellFolderViewDual"
>           ' it's a Windows Explorer window
>           set oFolder = oWin.document.folder
>           s = s & oFolder.self.path & "<br>"
>           oWin.Navigate "c:\"
>         Case Else
>           msgbox typename(oWin.document) & vbcrlf & oWin.locationURL
>       end select
>     end if
>   next

>   idOut.innerHTML = s

> end sub

> </script><!----------------------- End Script ----->
> </head>

> <body id="idBody"><!-------------- Body ----------->
>   <DIV id='idMain'><!------------- UI Area -------->
>     <form>
>       <button id='idRefresh'
> style='width:100'>Refresh</button>??
>       <button id='idClose' style='width:100'
>          onclick='javascript:window.close();'>Close</button>
>     </form>
>     <hr size='1'>
>   </DIV>
>   <DIV id='idOut'><!------------ Output Area --->
>   </DIV>
> </body>

> </html>



Fri, 22 Apr 2005 13:42:47 GMT  
 Navigate to folder in current Windows Explorer instance

Quote:
> Using WindowsXP and IE6, if that matters.

Must be an XP shell enhancement to IShellFolderViewDual (I'm running IE6sp1
on W2Ksp2).

Unfortunately, the MSDN Library documentation doesn't even mention
IShellFolderViewDual2 so one would need to use an object browser to seem
what's new.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Sat, 23 Apr 2005 01:02:15 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Create new folder in current folder in explorer window

2. Get current instance of Internet Explorer

3. Displaying a file folder in the current explorer

4. OL2K VBA: Changing the current folder of the active explorer

5. Filtering the current folder in the Active Explorer

6. Dragging files or folders from my application into Windows Explorer

7. The current Instance or a second instance?

8. Access the Windows Explorer to select folder

9. Current FOlder, Current Message

10. Navigating in same explorer

11. Need Information - Explorer Bar like in Windows Explorer/Outlook Express

12. Navigating "active" Internet Explorer

 

 
Powered by phpBB® Forum Software