starlitsky Posted August 8, 2018 Share Posted August 8, 2018 (edited) The function Sleep(60000) used is due to the ShellExecuteWait() doesn't wait for the script terminate!! When I run the script the MsgBox will show immediately. Have anyone know the reason for this problem? Below is what my code looks like: ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file1.au3') MsgBox(0, "", "1 terminate") Sleep(60000) ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file2.au3') MsgBox(0, "", "2") Sleep(15000) ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file3.au3') MsgBox(0, "", "3") Sleep(10000) Thanks! Edited August 10, 2018 by starlitsky To improve my question describe Link to comment Share on other sites More sharing options...
Developers Jos Posted August 8, 2018 Developers Share Posted August 8, 2018 ShellExecute will wait until the process is terminated. In case you shell a process that requires elevated rights (Administrator) then the process will restart itself thus terminating the original process. That is an example why ShellExecuteWait() wouldn't wait for the re-shelled process. Other than that you are way to vague and the word sometimes is not very exact either. Give us an script that replicates your issue when you need exact details. 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 (edited) 15 hours ago, Jos said: ShellExecute will wait until the process is terminated. In case you shell a process that requires elevated rights (Administrator) then the process will restart itself thus terminating the original process. That is an example why ShellExecuteWait() wouldn't wait for the re-shelled process. Other than that you are way to vague and the word sometimes is not very exact either. Give us an script that replicates your issue when you need exact details. Thank for your reply! I apologize for my poor English, I try to explain my problem more detail here. more complete code: #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <winAPI.au3> #include <Clipboard.au3> #Include <ScreenCapture.au3> ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file1.au3') MsgBox(0, "", "file1 done") Sleep(60000) ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file2.au3') MsgBox(0, "", "file2 done") Sleep(30000) ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'C:\file3.au3') MsgBox(0, "", "file3 done") Sleep(10000) RunWait('cscript.exe "file4.vbs"') MsgBox(0, "", "file4 done") Sleep(10000) Exit 0 I didn't use #RequireAdmin because of some script can't use that function, it will lead to some problem (It's too detail to explain it), so I separated them to the different file to execute it sequentially. The file1 and file2 have the Mouseclick function, but when the Mouse still moving, the next line MsgBox was pop up immediately, it was mean that the file1's script doesn't terminate then Msgbox show, I want to know why the shellExecuteWait() seems not to wait for the process terminate. Is this describe more detail enough? Edited August 9, 2018 by starlitsky For more detail describe Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 5 hours ago, starlitsky said: Is this describe more detail enough? No, as this still is not something I can run myself to test/debug. Show everything needed to replicate the issue. 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...
Simpel Posted August 9, 2018 Share Posted August 9, 2018 (edited) Hi. As I understand you want the main script wait until the file1.au3 etc. is ending and exiting? But ShellExecuteWait() will only halt the main script until file1.au3 etc. are correctly started. Simpel Edited August 9, 2018 by Simpel Kind of deleting SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
TheSaint Posted August 9, 2018 Share Posted August 9, 2018 Not exactly sure why you are using ShellExecute like you are? Have you also tried RunWait? With ShellExecute it would be more usual to run in the following manner ... or just use RunWait if wanting to provide all paths. ShellExecuteWait('C:\file1.au3') But like Jos said, it is hard to determine what is going on, without more information. What are each of those scripts doing? Can we see the code in them? starlitsky 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 1 hour ago, Simpel said: As I understand you want the main script wait until the file1.au3 etc. is ending and exiting? But ShellExecuteWait() will only halt the main script until file1.au3 etc. are correctly started. 1 I thought it before, but sometimes the Msgbox will show until the script totally complete, so I get a little confused about the ShellExecuteWait(). What the function waiting about. If as you say just wait for the script correctly started, why another file will wait until the script completely finishes? Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 Again, show us a proper example we can play with that is showing the reported and please stop these speculations/questions/guesses, it really serves no purpose. 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 (edited) 2 hours ago, TheSaint said: Not exactly sure why you are using ShellExecute like you are? Have you also tried RunWait? Thank for your reply, I use RunWait() before, but I can't use RunWait() because I want to use #RequireAdmin just for necessary. So I separated theirs into the different file. For more detail, I just simply describe what my file do, because the code for some file has about thousands of line. And it's not the core of the problem. file1: Simple, just install the software. file2: Move the mouse to setup and login to the server. expandcollapse popup#include <file.au3> #include <FileConstants.au3> #RequireAdmin $hWnd = WinGetHandle("[ACTIVE]") $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", "08040804", "int", 1 + 0) ;set english IME DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", 0x50, "int", 1, "int", $ret[0]) $outputFile = FileOpen("output.txt", $FO_APPEND) If $outputFile = -1 Then ;MsgBox(0, "check", "Error!") Exit 1 EndIf Local $aPos = WinGetPos ("Program Manager") Sleep(300) MouseClick("right", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) MouseClick("primary", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) WinWait("login") WinActivate("login") Local $aPos = WinGetPos ("login") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) WinWait("choose") WinActivate("choose") Local $aPos = WinGetPos ("choose") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) WinWait("login") WinActivate("login") Local $aPos = WinGetPos ("login") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) Send("^a{DEL}") Sleep(300) Send("xxx.xxx.xxx.xxx{TAB}") Sleep(300) Send("^a{DEL}") Sleep(300) Send("xxx{TAB}") Sleep(300) Send("xxx") Sleep(300) Send("{ENTER}") Sleep(5000) FileWriteLine($outputFile, "(2) login complete!") Local $aPos = WinGetPos ("Program Manager") MouseClick("right", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) MouseClick("primary", $aPos[2]-11, $aPos[3]-22, 1) Sleep(10000) FileWriteLine($outputFile, "(3) update complete!") FileClose($outputFile) Exit 0 file3: Check all files under the target directory check for their rights. (thousands of lines and I think this is not reason about this question.) file4: Use VBScript get some information from excel file. file5, 6, 7, 8, 9 ...etc. another thing I do. The file1 and file2 will show Msgbox immediately, but file3, file4... won't, then 7, 8, 9 just the case like file1 and file2. Edited August 9, 2018 by starlitsky more detail Link to comment Share on other sites More sharing options...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 (edited) 32 minutes ago, Jos said: Again, show us a proper example we can play with that is showing the reported and please stop these speculations/questions/guesses, it really serves no purpose. Thank for your advice, I will improve my problem describe, but I just need the time to organize/translate/and type the words. I have tried to describe more detail above. Edited August 9, 2018 by starlitsky Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 18 minutes ago, starlitsky said: I have tried to describe more detail above. All we need is the scripts that cause the issue and you have them....right? 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 2 minutes ago, Jos said: All we need is the scripts that cause the issue and you have them....right? I just put them above? Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 So there is a #requireadmin there. Does that mean you get the UAC prompt for it 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 (edited) 1 hour ago, starlitsky said: file1: Simple, just install the software. ... file2: Move the mouse to setup and login to the server. expandcollapse popup#include <file.au3> #include <FileConstants.au3> #RequireAdmin $hWnd = WinGetHandle("[ACTIVE]") $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", "08040804", "int", 1 + 0) ;set english IME DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", 0x50, "int", 1, "int", $ret[0]) $outputFile = FileOpen("output.txt", $FO_APPEND) If $outputFile = -1 Then ;MsgBox(0, "check", "Error!") Exit 1 EndIf Local $aPos = WinGetPos ("Program Manager") Sleep(300) MouseClick("right", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) MouseClick("primary", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) WinWait("login") WinActivate("login") Local $aPos = WinGetPos ("login") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) WinWait("choose") WinActivate("choose") Local $aPos = WinGetPos ("choose") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) WinWait("login") WinActivate("login") Local $aPos = WinGetPos ("login") MouseClick("primary", $aPos[0]+111, $aPos[1]+22, 1) Sleep(300) Send("^a{DEL}") Sleep(300) Send("xxx.xxx.xxx.xxx{TAB}") Sleep(300) Send("^a{DEL}") Sleep(300) Send("xxx{TAB}") Sleep(300) Send("xxx") Sleep(300) Send("{ENTER}") Sleep(5000) FileWriteLine($outputFile, "(2) login complete!") Local $aPos = WinGetPos ("Program Manager") MouseClick("right", $aPos[2]-111, $aPos[3]-22, 1) Sleep(300) MouseClick("primary", $aPos[2]-11, $aPos[3]-22, 1) Sleep(10000) FileWriteLine($outputFile, "(3) update complete!") FileClose($outputFile) Exit 0 file3: Check all files under the target directory check for their rights. (thousands of lines and I think this is not reason about this question.) 1 Edited August 9, 2018 by starlitsky Link to comment Share on other sites More sharing options...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 (edited) 6 minutes ago, Jos said: So there is a #requireadmin there. Does that mean you get the UAC prompt for it I turn off the UAC in advance. file1 and file2 have #RequireAdmin, but file3 can't use it, due to this so I separated them into different files. Edited August 9, 2018 by starlitsky Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 But that probably still means that the process is restarted to gain elevated rights thus terminated the original shelled process. What I normally do in this case is create a TempFIle before starting the elevated script and keep monitoring its existence. The shelled script will delete that tempfile at the end of it. Jos starlitsky 1 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 8 minutes ago, Jos said: But that probably still means that the process is restarted to gain elevated rights thus terminated the original shelled process. What I normally do in this case is create a TempFIle before starting the elevated script and keep monitoring its existence. The shelled script will delete that tempfile at the end of it. Thank for your advice, let me search for more detail about how to create the temp file. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2018 Developers Share Posted August 9, 2018 (edited) Here is a simple example of hat I mean: FileDelete("file1.au3") ; create tempfile to monitor $Tempfile= @TempDir & "\demo.txt" FileWriteLine($Tempfile,"Dummy") ; create demo file1.au3 script FileWriteLine("file1.au3",'#RequireAdmin') FileWriteLine("file1.au3",'msgbox(0,"file1","file1")') FileWriteLine("file1.au3",'FileDelete(@TempDir & "\demo.txt")') ; run script elevated ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\autoit3.exe', 'file1.au3') ; monitor file1.au3 is filished While FileExists($Tempfile) sleep(100) WEnd MsgBox(0, "", "file1 done") Jos Edited August 9, 2018 by Jos starlitsky 1 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...
starlitsky Posted August 9, 2018 Author Share Posted August 9, 2018 5 minutes ago, Jos said: Here is a simple example of hat I mean OK, I got it. I will try this solution. If my problem was solved I will change the Title of this topic. Thanks for everyone's help. 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