bighero Posted July 11, 2015 Share Posted July 11, 2015 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...TIARich Link to comment Share on other sites More sharing options...
Developers Jos Posted July 11, 2015 Developers Share Posted July 11, 2015 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 More sharing options...
bighero Posted July 11, 2015 Author Share Posted July 11, 2015 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... Link to comment Share on other sites More sharing options...
bighero Posted July 11, 2015 Author Share Posted July 11, 2015 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 11, 2015 Developers Share Posted July 11, 2015 Why do you want to use the ProcessWait & close in this way?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 More sharing options...
bighero Posted July 11, 2015 Author Share Posted July 11, 2015 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 More sharing options...
Developers Jos Posted July 11, 2015 Developers Share Posted July 11, 2015 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 More sharing options...
MilesAhead Posted July 12, 2015 Share Posted July 12, 2015 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. My Freeware Page Link to comment Share on other sites More sharing options...
JohnOne Posted July 12, 2015 Share Posted July 12, 2015 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) NextOr 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now