Jump to content

Explorer.exe duplicates after "run" command


Recommended Posts

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

Link to comment
Share on other sites

  • Developers

Try if this work better for you:

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...