Jump to content
Sign in to follow this  
bighero

Explorer.exe duplicates after "run" command

Recommended Posts

bighero

Hi all,

I have a code snippet that highlights a nominated file/dir using the Run command and explorer.exe:

Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)

The problem I'm having is that, after it's run, the explorer.exe session is left open. I only noticed this after a few hours of testing my script and found about 90 such duplicates. I've tried process close using the PID but no luck. I've also got RequireAdmin just in case it was a perm thing.

So my question is, is there a correct way to be using using the explorer session that I'm just not following, or is there another reliable method I can use to highlight a file/folder that doesn't involve explorer?

I'd looked at comparing a process list before and after, then closing the additional processes, but couldn't get it to work...

TIA

Rich

Share this post


Link to post
Share on other sites
Jos

Try if this work better for you:

Local $iPid = ShellExecute('explorer.exe ','/n,/e,/select,"' & $filepath &'"')

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
bighero

I think I get it, so you think explorer is staying open to look for additions to the command?

Thanks for the reply, I'll give this a go right now...

Share this post


Link to post
Share on other sites
bighero

Sorry, no luck.

I've separated out the code to the following, so I know it's nothing to do with the rest of the script...

$filepath = "E:\"
Local $iPid = ShellExecute('explorer.exe ','/n,/e,/select,"' & $filepath &'"')
ProcessWait($iPid)
ProcessClose($iPid)

...and it just keeps adding explorer instances.

Share this post


Link to post
Share on other sites
bighero

I've got the processWait to check the proc is running before I right click on the file and do some other stuff with it, the ProcessClose then comes a little while later.

I've just added a message box with content of ProcessExists($iPid) and it comes back as 0, so there's a child explorer session opened and that's what's remaining?

Share this post


Link to post
Share on other sites
Jos

It seems that the returned process is not the process used for the shown explorer window, so that will not work.
When it is about selecting a file you could use FileSaveDialog() and use the returned selected file.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
MilesAhead

I've got the processWait to check the proc is running before I right click on the file and do some other stuff with it, the ProcessClose then comes a little while later.

I've just added a message box with content of ProcessExists($iPid) and it comes back as 0, so there's a child explorer session opened and that's what's remaining?

Did you output the value of the PID?  It may be returning -1.

 

Share this post


Link to post
Share on other sites
JohnOne

You could just use an existing explorer window...

; Modified from https://www.autoitscript.com/forum/topic/162905-automating-windows-explorer/

; Windows Explorer on XP, Vista, 7, 8
$hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]")
If Not $hExplorer Then Exit

; Shell object
$oShell = ObjCreate("Shell.Application")

; Find window
For $oWindow In $oShell.Windows()
    If $oWindow.HWND() = $hExplorer Then
        $oWindow.Navigate("C:\")
        Exit
    EndIf
Next

; Selected items
For $oItem In $oWindow.Document.SelectedItems()
    ConsoleWrite($oItem.Path() & @CRLF)
Next

Or I'm sure you could create a new window object through the shell and destroy it when needed.

Reading that whole thread and looking through examples might wise you up to that.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  

×