neazoi Posted April 24, 2015 Posted April 24, 2015 (edited) I use Run("explorer.exe " & @ScriptDir&"DataText_received_files"); How can I detect this specific explorer window process id and wait until this specific explorer window is closed? ProcessExists does not seem to work for specific window, unless I am doing something wrong Edited April 24, 2015 by neazoi
InunoTaishou Posted April 24, 2015 Posted April 24, 2015 (edited) Can WinExist not do what you need? Go by title/class? Edited April 24, 2015 by InunoTaishou
Developers Jos Posted April 24, 2015 Developers Posted April 24, 2015 The Run command returns the PID so you should be able to monitor that. 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.
neazoi Posted April 26, 2015 Author Posted April 26, 2015 (edited) The Run command returns the PID so you should be able to monitor that.JosI can't. A little help is appreciated.Here is my code snipet.Local $previewWin = Run("explorer.exe " & @ScriptDir&"\DataText_received_files");open explorer to see extracted files in folder While ProcessExists($previewWin) Wend DirRemove(@ScriptDir&"\DataText_received_files",1); when files have been viewed, delete the DataText_received_files dir DirCreate(@ScriptDir&"\DataText_received_files");recreate the DataText_received_files dirAlso the next code did not work satisfactorily. The while loop is not good as well. I want to say: as long as this explorer window is open wait (if it closes then continue script)Run("explorer.exe " & @ScriptDir&"\DataText_received_files");open explorer to see extracted files in folder Local $hWnd = WinWait("[CLASS:Explorer]", "", 60); Wait seconds for the window to appear. Local $iPID = WinGetProcess($hWnd); Retrieve the PID of process using the window handle returned by WinWait. While ProcessExists($iPID) Sleep(100) Wend WinClose($hWnd) DirRemove(@ScriptDir&"\DataText_received_files",1); when files have been viewed, delete the DataText_received_files dir DirCreate(@ScriptDir&"\DataText_received_files");recreate the DataText_received_files dir Edited April 26, 2015 by neazoi
JohnOne Posted April 26, 2015 Posted April 26, 2015 Explorer.exe handles all windows. Use ShellExecute and wait for the window by it's title. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
neazoi Posted April 27, 2015 Author Posted April 27, 2015 (edited) Explorer.exe handles all windows. Use ShellExecute and wait for the window by it's title.Exactly, that is the problem. Can you please give me a short example code for this? Edited April 27, 2015 by neazoi
UEZ Posted April 27, 2015 Posted April 27, 2015 ShellExecuteWait("Calc.exe") MsgBox(0, "Test", "Calc.exe has been closed") Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
jguinch Posted April 27, 2015 Posted April 27, 2015 When I run explorer.exe with a directory as parameter, the PID returned by run is not PID used by the explorer window.You can try something like this :$sDir = @ScriptDir & "\DataText_received_files" Run("explorer.exe " & $sDir) $hExplorer = WinWait("[REGEXPTITLE:(?i)\Q" & $sDir & "\E$]") WinWaitClose($hExplorer) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
neazoi Posted April 27, 2015 Author Posted April 27, 2015 When I run explorer.exe with a directory as parameter, the PID returned by run is not PID used by the explorer window.You can try something like this :$sDir = @ScriptDir & "\DataText_received_files" Run("explorer.exe " & $sDir) $hExplorer = WinWait("[REGEXPTITLE:(?i)\Q" & $sDir & "\E$]") WinWaitClose($hExplorer) This worked fine!However Windows have the option to set the explorer window title to be the full path or just the name of the last folder you are in.For example in my case, I had to do it like this:Local $sDir = @ScriptDir & "\DataText_received_files" Local $windowtitle = "DataText_received_files" Run("explorer.exe " & $sDir);open explorer to see extracted files in folder Local $hExplorer = WinWait("[REGEXPTITLE:(?i)\Q" & $windowtitle & "\E$]") WinWaitClose($hExplorer) DirRemove(@ScriptDir&"\DataText_received_files",1); when files have been viewed, delete the DataText_received_files dir DirCreate(@ScriptDir&"\DataText_received_files");recreate the DataText_received_files dirI wonder if there is a way to check both cases, so that the program works in either explorer setting?
SadBunny Posted April 27, 2015 Posted April 27, 2015 (edited) Change the regular expression to whatever you need. But have you tried the code you have there with both options? Because as far as I can tell, it should already work with both options as you have it there./edit: although if you were to navigate into another folder, the WinWaitClose thinks it's done (because there is no longer a window matching that title definition), and the script continues, even though your explorer window is actually still present (just with another folder in the title). That may not be what you want. One fix would be to remove the $ from your regex so that the regex, written like this at least, effectively changes to "contains" instead of "must end with". Then you could enter subfolders. But if you were to leave your folder (i.e. "go up one"), the WinWaitClose would still think it was done. Depending on what you plan to do in that explorer window, you may need a slightly more advanced approach.Never mind all that, I'm a dummy. The current code already gets the windows handle and waits for that to close, so you can safely navigate. Edited April 27, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
neazoi Posted April 27, 2015 Author Posted April 27, 2015 Change the regular expression to whatever you need. But have you tried the code you have there with both options? Because as far as I can tell, it should already work with both options as you have it there.Yes, both code snippets work fine, but the first works if the explorer window title is @ScriptDir & "\DataText_received_files"whereas the second one works if the explorer window title is "DataText_received_files".This setting depends on the user (how he has set the explorer windows titles to appear).You mention changing the regular expression, can this be used to include both case?A bit of code would be appreciated.
SadBunny Posted April 27, 2015 Posted April 27, 2015 (edited) What I mean is that it looks like the last piece of code you posted should in fact already work in both modes. The first one (from jguinch) only works in full-path-mode.The regex in "[REGEXPTITLE:(?i)\Q" & $windowtitle & "\E$]" means:1) the title should end with whatever is in $windowtitle (because it's a string followed by $).2) the match is to be done case-insensitively with (?i)3) any special regex-specific characters in $windowtitle should be interpreted as literal characters (the \Q...\E)As far as I can tell, that should match any window that ends with the folder name, no matter whether there is a path in front of it (or a Zen koan, or the entire King James bible). Edited April 27, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
neazoi Posted April 27, 2015 Author Posted April 27, 2015 What I mean is that it looks like the last piece of code you posted should in fact already work in both modes. The first one (from jguinch) only works in full-path-mode. You are absolutely right!It worked in both cases. A big thanks to all of you.
jguinch Posted April 27, 2015 Posted April 27, 2015 (edited) neazoi : can you explain us what you are trying to automate with the explorer ? There are a lot of function for file/folder automation.You can also try this one, which use a registry check to find if the explorer displays the full path or no. And I had REGEXPCLASS to work only with the explorer (I know CabinetWClass and ExploreWClass classes, but there are certainly others, depending of the OS version) $sDir = "c:\temp" $iFullPath = Number(RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState", "FullPath")) Run("explorer.exe " & $sDir);open explorer to see extracted files in folder $sTitle = $iFullPath ? $sDir : StringRegExpReplace($sDir, ".*\\", "") Local $hExplorer = WinWait("[REGEXPCLASS:(?i)ExploreWClass|CabinetWClass; REGEXPTITLE:(?i)\Q" & $sTitle & "\E$]") WinWaitClose($hExplorer) Edited April 27, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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