LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Close execution of .exe started with SystemExec

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

0 Kudos
Message 1 of 17
(320 Views)

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 17
(301 Views)

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.

0 Kudos
Message 3 of 17
(271 Views)

What is the output of taskkill? I tried it and it works with notepad.exe

0 Kudos
Message 4 of 17
(264 Views)

@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

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 17
(248 Views)

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".

 

0 Kudos
Message 6 of 17
(223 Views)
0 Kudos
Message 7 of 17
(216 Views)

@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.

Message 8 of 17
(189 Views)

This VI is missing "PostMessage Master.vi".

0 Kudos
Message 9 of 17
(176 Views)

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.

0 Kudos
Message 10 of 17
(155 Views)