gerwim 0 Posted October 18, 2010 Hi there, So I'm starting a .bat file which is a CMD process. I give this process a PID variable and trying to close it doesn't work. This is my code: Func Start() Global $PID = Run("server_nogui.bat", "") GUICtrlSetState($BTN_Restart, $GUI_ENABLE) GUICtrlSetState($BTN_Stop, $GUI_ENABLE) GUICtrlSetState($BTN_Start, $GUI_DISABLE) GUICtrlSetData($status, "Running") EndFunc Func Stop() MsgBox(0,"Debug","PID: "& $PID) ProcessClose($PID) GUICtrlSetState($BTN_Restart, $GUI_DISABLE) GUICtrlSetState($BTN_Stop, $GUI_DISABLE) GUICtrlSetState($BTN_Start, $GUI_ENABLE) GUICtrlSetData($status, "Stopped") EndFunc The process keeps running, but when I do for example ProcessClose("excel.exe") it works.. Google didn't help me either. Thanks in advance! Share this post Link to post Share on other sites
iamtheky 927 Posted October 18, 2010 That works fine (see below). The problem lies elsewhere. Maybe the contents of the batch? Global $PID If fileexists(@ScriptDir & "\test.bat") Then FileDelete(@ScriptDir & "\test.bat") sleep (1000) Endif _Make () _Start () _Stop() Func _Make() filewrite (@ScriptDir & "\test.bat" , "echo test" & @CRLF & "pause") sleep (1000) EndFunc Func _Start() Global $PID = Run("test.bat", "") sleep (2000) EndFunc Func _Stop() MsgBox(0,"Debug","PID: "& $PID) ProcessClose($PID) If Not ProcessExists ($PID) Then MsgBox(0,"Closed","PID: "& $PID & " has been closed") Endif EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
gerwim 0 Posted October 18, 2010 Hmm this is very strange. Could it be that it's not having a pause or something? Since I do have the PID, it just doesn't close it. Share this post Link to post Share on other sites
gerwim 0 Posted October 18, 2010 This code does work: WinKill("C:\WINDOWS\system32\cmd.exe") This is fine for me too, BUT if someone has a different windows folder or different windows drive, it doesn't work.. Any other way? Share this post Link to post Share on other sites
willichan 220 Posted October 18, 2010 This code does work: WinKill("C:\WINDOWS\system32\cmd.exe") This is fine for me too, BUT if someone has a different windows folder or different windows drive, it doesn't work.. Any other way? @WindowsDir Join me in supporting Pediatric Therapy Network through Amazon Smile. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator Share this post Link to post Share on other sites
iamtheky 927 Posted October 18, 2010 WinTitleMatchMode, 2 should just let you call it ('cmd') or call it with "cmd /c" from within the batch so that it terminates itself ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
gerwim 0 Posted October 18, 2010 @WindowsDirHehe, why I didn't thought of that. /facepalm. Thanks =)WinTitleMatchMode, 2 should just let you call it ('cmd')or call it with "cmd /c" from within the batch so that it terminates itselfAwesome, I used the match mode, works like a charm =) Share this post Link to post Share on other sites