Sign in to follow this  
Followers 0
gerwim

ProccesClose not able to close cmd.exe

7 posts in this topic

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



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

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

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

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

Share this post


Link to post
Share on other sites

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

@WindowsDir

Hehe, 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 itself

Awesome, I used the match mode, works like a charm =)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0