Terenz Posted July 7, 2014 Share Posted July 7, 2014 Hi guys. I have this code: Local $iPID, $iPID2, $hWnd, $iFound $aPIDstart = ProcessList("myprocess.exe") RunWait("myprocess.exe /parameter", @ScriptDir, @SW_HIDE) $aPIDend = ProcessList("myprocess.exe") For $i = 1 To UBound($aPIDend) - 1 $iFound = False For $i2 = 1 To UBound($aPIDstart) - 1 If $aPIDstart[$i2][1] = $aPIDend[$i][1] Then $iFound = True Next If $iFound = False Then $iPID = $aPIDend[$i][1] Next $aWinlist = WinList() For $i = 1 To $aWinlist[0][0] If $aWinlist[$i][0] <> "" Then $iPID2 = WinGetProcess($aWinlist[$i][1]) If $iPID2 = $iPID Then $hWnd = $aWinlist[$i][1] ExitLoop EndIf EndIf Next ConsoleWrite("PID: " & ProcessExists($iPID) & @CRLF) ConsoleWrite("HANDLE: " & $hWnd & @CRLF) ConsoleWrite("TITLE: " & WinGetTitle($hWnd) & @CRLF) Pratically it works the 90% of times, sometime it take the wrong process-window ( i'll check the consolewrite ) and my real function fail and i don't know what is the cause There is something wrong in the code? Thanks Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
BrewManNH Posted July 7, 2014 Share Posted July 7, 2014 What is this supposed to be doing? Because your process won't show in the array $aPIDend because it won't get to the second processlist until your process has ended. $aPIDstart = ProcessList("myprocess.exe") ; next line causes the script to pause until the RunWait process has ended RunWait("myprocess.exe /parameter", @ScriptDir, @SW_HIDE) ; this array should have the same list as the previous call to processlist $aPIDend = ProcessList("myprocess.exe") If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Terenz Posted July 7, 2014 Author Share Posted July 7, 2014 (edited) I need the handle-pid of the process, the problem is there are multiple processes at the same time. So the idea was: 1) Check all process of myprocess.exe, example there are 5 2) Launch another instance of myprocess.exe and wait before it completly start for continue the script. If runwait is not the correct approach, how can i know if the process has started before do point 3? 3) Do again, re-check all process of myprocess.exe, now there are 6, 5 before, so comparing the pid i know what is the "new" process 4) Do a func() on the script, is replaced by ConsoleWrite() 5) Close the "new" process for restore the initial situation Thanks, i hope is clear now Edited July 7, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
BrewManNH Posted July 7, 2014 Share Posted July 7, 2014 The Run command returns the PID of the process you run with it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Terenz Posted July 7, 2014 Author Share Posted July 7, 2014 Yeah i know but the returning PID of Run() is not correspondig with the real PID, that's the reason of that script Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jdelaney Posted July 7, 2014 Share Posted July 7, 2014 How about trying this, with the PID from the Run command: _WinAPI_EnumChildProcess IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Terenz Posted July 7, 2014 Author Share Posted July 7, 2014 (edited) Nope, not work. This is another test: Local $iPID, $iPID2, $aPIDStart, $aPIDEnd, $hWnd $aPIDStart = ProcessList("myprocess.exe") If @error Or $aPIDStart[0][0] = 0 Then Exit ConsoleWrite("-Number of starting myprocess.exe process: " & $aPIDStart[0][0] & @CRLF) Run("myprocess.exe /parameter", @ScriptDir, @SW_HIDE) Do $aPIDEnd = ProcessList("myprocess.exe") Sleep(10) Until $aPIDEnd[0][0] = $aPIDStart[0][0] + 1 ConsoleWrite("!Number of myprocess.exe process after Run: " & $aPIDend[0][0] & @CRLF) For $i = 1 To UBound($aPIDEnd) -1 ConsoleWrite("$aPIDend: " & $aPIDend[$i][1] & @CRLF) Next ConsoleWrite(@CRLF) For $i = 1 To UBound($aPIDStart) - 1 ConsoleWrite("$aPIDStart: " & $aPIDStart[$i][1] & @CRLF) Next ConsoleWrite(@CRLF) ConsoleWrite("The PID i need is:" & $aPIDend[UBound($aPIDEnd)-1][1] & @CRLF) For what i have see the real PID i need is always the last of the $aPiDend: -Number of starting myprocess.exe process: 9 !Number of myprocess.exe process after Run: 10 $aPIDend: 456 $aPIDend: 2940 $aPIDend: 712 $aPIDend: 2448 $aPIDend: 1380 $aPIDend: 748 $aPIDend: 2636 $aPIDend: 496 $aPIDend: 768 $aPIDend: 508 $aPIDStart: 456 $aPIDStart: 2940 $aPIDStart: 712 $aPIDStart: 2448 $aPIDStart: 1380 $aPIDStart: 748 $aPIDStart: 2636 $aPIDStart: 496 $aPIDStart: 768 The PID i need is:508 Plaese someone can check and confirm on your o.s if is the same? Thanks Edited July 7, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jdelaney Posted July 7, 2014 Share Posted July 7, 2014 (edited) You didn't try my suggestion. We can't try, because your script is not reproducible...no idea what myprocess.exe is. Good luck. ; download from forums: #include <WinAPIex.au3> $ipid = Run("cmd") While True MsgBox(1,1,"start some process in the command prompt...like notepad") $a = _WinAPI_EnumChildProcess($ipid) _ArrayDisplay($a) Sleep(1000) WEnd will return processes you start through the command prompt Edited July 7, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Terenz Posted July 7, 2014 Author Share Posted July 7, 2014 (edited) jdelaney i have try your suggestion before open this thread, i have write "nope, not work" for a reason Sure my script is reproducible, open a couple of notepad.exe ( one is enought but 4-5-6 are better ) then launch a notepad with mine script and see if the returned pid of notepad ( by Run, just add a variable ) is the same of $aPIDend[uBound($aPIDEnd)-1][1] Thanks Edited July 7, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jdelaney Posted July 7, 2014 Share Posted July 7, 2014 Next time, modify your script for such a suggestion. We are here to help, not create our own debugging to prove a point. I'd be happy to show you your error, if you make a reproducable script. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Terenz Posted July 7, 2014 Author Share Posted July 7, 2014 Debugging what? Lol i have explained what to do, but if it so hard i'll explain better, it's not a problem but i'm on a phone i can't put the tags: Replace this line: Run("myprocess.exe /parameter", @ScriptDir, @SW_HIDE) With this: $var = Run("notepad.exe", @ScriptDir, @SW_HIDE) Replace this line: ConsoleWrite("The PID i need is:" & $aPIDend[uBound($aPIDEnd)-1][1] & @CRLF) With this: ConsoleWrite("The PID i need is:" & $aPIDend[uBound($aPIDEnd)-1][1] & " is equal to? " & $var & @CRLF) Before start the script, as i say before, open some instance of notepad. If $var = $aPIDend[uBound($aPIDEnd)-1][1] i can put the thread as solved Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Solution jdelaney Posted July 7, 2014 Solution Share Posted July 7, 2014 Did that, works fine. Obviously, I can't reproduce with your issue, so you are not explaining it correctly, or are not providing a proper script...Oh, and multiple other changes were required to make your script work for notepad. Output The PID i need is:9348 is equal to? 9348 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Terenz Posted July 8, 2014 Author Share Posted July 8, 2014 Thanks Nothing is so strong as gentleness. Nothing is so gentle as real strength 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