Jump to content

Recommended Posts

Posted

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!

Posted

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

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

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.

Posted

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?

Posted

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
Posted

WinTitleMatchMode, 2 should just let you call it ('cmd')

or call it with "cmd /c" from within the batch so that it terminates itself

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

@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 =)

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
×
×
  • Create New...