Nemcija Posted January 12, 2007 Share Posted January 12, 2007 I have got a problem here with ProcessClose.I'm writing a program which starts an other program, works with it an closes it again, if the process is finished.The code looks like this:;~ [...] #include <Process.au3> ;~ [...] Func _runcheckroutinefunction($_pid) ;~ isn't needed to post it here, because it is too long and not the problem ;~ works absolutely correctly ;) EndFunc $pid = run("program.exe") ;~ [...] While _runcheckroutinefunction($pid) = 1 ProcessClose($pid) Sleep(100) ;~ And this loop will only end if i close the process in taskmanager WEndPlease don't tell me that i should use ProcessClose("program.exe") (of course it works !!) because there are more of this, so i have to close exactly this PID.But it dosent work Thank you for helping.Greetings, Nemcija. [url=www.vergessene-welt.de][/url] Link to comment Share on other sites More sharing options...
NeoFoX Posted January 12, 2007 Share Posted January 12, 2007 run("program.exe") $pid = ProcessExists("program.exe") While _runcheckroutinefunction($pid) = 1 ProcessClose($pid) Sleep(100) ;~ And this loop will only end if i close the process in taskmanager WEnd though it had to be like this... Neo [center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center] Link to comment Share on other sites More sharing options...
xcal Posted January 12, 2007 Share Posted January 12, 2007 (edited) I doubt that would work the way it is, since ProcessExists returns the pid which won't be 1. $app = 'program.exe' While ProcessExists($app) ProcessClose($app) Sleep(100) ;~ And this loop will only end if i close the process in taskmanager WEnd edit - forgot something. And that should give you an idea of how maybe to work it in to your function. Edited January 12, 2007 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 12, 2007 Moderators Share Posted January 12, 2007 @Nemcija - Some processes can only be forced to close, thus you have to use something like this. ShellExecuteWait("taskkill", "/F /PID " & $PID) Link to comment Share on other sites More sharing options...
herewasplato Posted January 12, 2007 Share Posted January 12, 2007 (edited) Separate your trouble shooting from your script.How does this work for you?<dumb code removed>Edit: my bad - according to the help file under ProcessCloseReturn ValueNone. (Returns 1 regardless of success/failure.) Edited January 12, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 12, 2007 Moderators Share Posted January 12, 2007 (edited) @NeoFoX - The Run() function returns a PID as well, so the way he is doing it is fine.---@xcal - It doesn't have to be "1", the expression just has to evaluate to true for the loop to continue. With that in mind any string or positive integer will evaluate as true. Edited January 12, 2007 by big_daddy Link to comment Share on other sites More sharing options...
Nemcija Posted January 12, 2007 Author Share Posted January 12, 2007 (edited) @Neo: I have got the PID. Run returns the PID! @xcal: It is the same as ProcessClose("program.exe") please read my post first, but thanks. @big_daddy: Is "taskkill" a windows function? @herewasplato: doesn't work that is exactly what i'm doing up there, but it doesn't work. Thanks, Greetings Nemcija. Edited January 12, 2007 by Nemcija [url=www.vergessene-welt.de][/url] Link to comment Share on other sites More sharing options...
herewasplato Posted January 12, 2007 Share Posted January 12, 2007 Does WinClose or WinKill do anything for you? [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Nemcija Posted January 12, 2007 Author Share Posted January 12, 2007 (edited) Does WinClose or WinKill do anything for you?No because every "program.exe" have the same title.So any random process would be closed.But i think that ShellExecuteWait("taskkill", "/F /PID " & $PID) will do it. My only problem at the moment is, that "taskkill" has to be available on any computer. Edited January 12, 2007 by Nemcija [url=www.vergessene-welt.de][/url] Link to comment Share on other sites More sharing options...
herewasplato Posted January 12, 2007 Share Posted January 12, 2007 No because every "program.exe" have the same title.So any random process would be closed.Can you change the title for the window that you are working with? [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Nemcija Posted January 12, 2007 Author Share Posted January 12, 2007 i can't change it. Because is there anywhere another window with the same title as the title of "program.exe" it be replaced. p.e.: anotherprogram.exe Title: "bla" program.exe Title: "bla" WinSetTitle("bla","","bla bla") -> anotherprogram.exe Title: "bla bla" do you understand? [url=www.vergessene-welt.de][/url] Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 12, 2007 Moderators Share Posted January 12, 2007 Looks like it's only available on Microsoft Windows XP professional or Windows 2003. Link to comment Share on other sites More sharing options...
Nemcija Posted January 12, 2007 Author Share Posted January 12, 2007 Ok then i will do it like this .. func _CloseAPP($_closeapp_appname="",$_closeapp_pid=-1) If FileExists(@WindowsDir&"\system32\taskkill.exe") Then if $_closeapp_pid > 0 and procsreq($_closeapp_appname,"run",$_closeapp_pid) <> 0 Then ShellExecuteWait("taskkill", "/F /PID " & $_closeapp_pid,"","",@SW_HIDE) EndIf if $_closeapp_pid > 0 and procsreq($_closeapp_appname,"run",$_closeapp_pid) <> 0 Then ProcessClose($_closeapp_pid) if $_closeapp_appname <> "" and procsreq($_closeapp_appname,"run",$_closeapp_pid) <> 0 Then ProcessClose($_closeapp_appname) If $_closeapp_pid > 0 and procsreq($_closeapp_appname,"run",$_closeapp_pid) <> 0 Then WinKill(procsreq($_closeapp_appname,"title",$_closeapp_pid)) EndFunc procsreq is the real name of _runcheckroutinefunction() it returns much more things than only that the program runs or not Thank you big daddy an the others, too. Greetings Nemcija. [url=www.vergessene-welt.de][/url] Link to comment Share on other sites More sharing options...
herewasplato Posted January 12, 2007 Share Posted January 12, 2007 i can't change it.Because is there anywhere another window with the same title as the title of "program.exe" it be replaced.p.e.:anotherprogram.exe Title: "bla"program.exe Title: "bla"WinSetTitle("bla","","bla bla") -> anotherprogram.exe Title: "bla bla"do you understand?It looks like you have your work around... but I think that there is a way to know which window is associated with a given PID. You would only change the window title associated with the process that the script started....later... [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
xcal Posted January 12, 2007 Share Posted January 12, 2007 @xcal - It doesn't have to be "1", the expression just has to evaluate to true for the loop to continue. With that in mind any string or positive integer will evaluate as true.Heh ya, I realized that about 1 minute after I left my PC and went to bed. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
improbability_paradox Posted January 12, 2007 Share Posted January 12, 2007 (edited) Func _GetWHNDLFromPID($PID) Local $wHndl="", $WCCount=0 Do Sleep(50) if $WCCount > 400 Then Return -1 Local $WList=WinList() for $WLCount= 1 to $WList[0][0] if WinGetProcess($WList[$WLCount][1])=$PID Then $wHndl=$WList[$WLCount][1] ExitLoop EndIf Next $WCCount += 1 Until not($wHndl="") Return $wHndl EndFunc using this function, you can obtain the Handle of a window Associated with a specific PID. Once obtained, you can do a simple winclose($wHndl) to close only that window. One thing to note; I wrote this particular function intending that it would only need to find the Hndl of one window. If the process has more than one window associated with it, you may have to either re-work the function so that it will return multiple handles, or call the function more than once. Edit: Minor correction to code Edited January 12, 2007 by improbability_paradox 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