08-28-2025 04:44 AM
Hello. I used the SystemExec function to launch a .bat file that opens an application (MyProgram.exe file). Then I see that the application run in the black window (like the command prompt window). In the upper part of the window it's called as "C:\WINDOWS\system32\cmd.exe".
I need to close the execution of MyProgram.exe after a fixed time. I tried some test with the SystemExec function but I haven't found a solution.
Inside the .bat file there is only this line:
@MyProgram.exe -v
08-28-2025 05:29 AM
Use the taskkill program. Launch another cmd with this command line:
cmd /c taskkill /IM MyProgram.exe
Of course, this will abruptly terminate MyProgram.
Generally speaking, the best way would be to be able to send a "message" (e.g. using UDP) to MyProgram.exe that would terminate itself.
08-28-2025 06:39 AM - edited 08-28-2025 06:40 AM
I tried but it opens for an instant a new black window and then close it, but the original one with the execution of the program remains open.
08-28-2025 06:51 AM
What is the output of taskkill? I tried it and it works with notepad.exe
08-28-2025 07:38 AM
@V.Life ha scritto:
I tried but it opens for an instant a new black window and then close it, but the original one with the execution of the program remains open.
Try
taskkill /IM etc.
in a standard command prompt window and see what happens
08-28-2025 09:39 AM
I used the SystemExec block with this command line:
cmd /c /taskkill /IM MyProgram.exe
The value of return code of the SystemExec block is 1, standard error is "Not found".
08-28-2025 09:55 AM
You can close a window more properly using Windows API:
08-29-2025 12:00 AM
@V.Life wrote:
I used the SystemExec block with this command line:
cmd /c /taskkill /IM MyProgram.exe
The value of return code of the SystemExec block is 1, standard error is "Not found".
First, you should remove the forward slash / before taskkill:
cmd /c /taskkill /IM MyProgram.exe
Second, you can add the /F switch to forcefully end the process:
cmd /c taskkill /F /IM MyProgram.exe
Refer to the taskkill documentation.
Also, keep in mind that if the process you want to kill is running with higher privileges, you cannot terminate it with taskkill from a program with lower privileges — this is obvious and expected behavior.
08-29-2025 01:16 AM
This VI is missing "PostMessage Master.vi".
08-29-2025 04:42 AM
Out of Labview I managed to open and close the prompt window using PowerShell. Can I use the SystemExec block to launch it and execute the same commands that I tried out of Labview? Thanks.