Sign in to follow this  
Followers 0
CrimsonRiot

Creating new windows explorer window

6 posts in this topic

How would I create a new explorer window to open a specific location, such as "c:\WINDOWS\system32\"?

Share this post


Link to post
Share on other sites



$dirPath = "c:\WINDOWS\system32"

If FileExists($dirPath) Then
      run("explorer.exe "& $dirPath)
Else
      MsgBox(0, "error", "Directory does not exist")
EndIf

<_<

Share this post


Link to post
Share on other sites

Make sure you put the path in quotes if it has spaces in it.

$dirPath = "c:\WINDOWS\system32"
If FileExists($dirPath) Then
      run('explorer.exe "'& $dirPath & '"')
Else
      MsgBox(0, "error", "Directory does not exist")
EndIf

Share this post


Link to post
Share on other sites

excellent! ty very much. I was on the right track, just needed a little push.

Share this post


Link to post
Share on other sites

Make sure you put the path in quotes if it has spaces in it.

$dirPath = "c:\WINDOWS\system32"
If FileExists($dirPath) Then
      run('explorer.exe "'& $dirPath & '"')
Else
      MsgBox(0, "error", "Directory does not exist")
EndIf
I didn't really bother as c:\WINDOWS\system32\ doesn't have any spaces in it <_<

Share this post


Link to post
Share on other sites

Another Method:

Local $dirPath = "c:\WINDOWS\system32"
If Not FileExists($dirPath) Then
      MsgBox(0, "Explorer Open - Error", "Directory does not exist: "&$dirPath)
      Exit
EndIf
$oShell = ObjCreate("shell.application") 
$oShell.open($dirPath)
;OR $oShell.explore($dirPath); this will get the explorerbar to open with the Folders toolbar

If you're interested in control it once it's opened

Local $dirPath = "c:\WINDOWS\system32"
If Not FileExists($dirPath) Then
      MsgBox(0, "Explorer Open - Error", "Directory does not exist: "&$dirPath)
      Exit
EndIf
$oShell = ObjCreate("shell.application") 
Local $oShellWindows = $oShell.windows
Local $currentTotal = $oShell.windows.count;First get the current explorer window count
Local $PreviousBound = $currentTotal-1;Used later
$oShell.open($dirPath);Open new
$PreviousBound +=1
        While 1;This will give it time to open (if you don't do this it will error out)
            Local $currentTotal = $oShell.windows.count
            ConsoleWrite('$currentTotal: '&$currentTotal & ' vs '&($PreviousBound+1)&@LF)
            If  $currentTotal = ($PreviousBound+1) Then
                ExitLoop
            EndIf           
            Sleep(100)          
        WEnd
Local $Window = $oShell.windows.item($PreviousBound)
Local $WindowHwnd = HWnd($window.HWnd());NOW you have the Handler for the new Explorer Window
; Examples for manipulation to the new Explorer Window
WinSetTitle($WindowHwnd,'','New Window')


MsgBox(0,'Explorer Command','Navigation to C:\ will take place in five seconds or on ok.',5)
$window.Navigate('C:\'); Notice how with the COM commands you don't use the HWnd

A decision is a powerful thing

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0