Opening / closing an application via a .bat file [Windows]

Good day, I have a .bat file that launches a specific application, and then after 5 seconds it will close / kill it.

I have it right now because he successfully opened the application, which, when opening the application, will not execute the rest of the commands if I do not close the application manually.

Here is my code:

cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\" asperascp.exe sleep 5 taskkill /IM asperascp.exe /f 

I am also trying to remove the sleep command.

 cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\" asperascp.exe taskkill /IM asperascp.exe /f 

But he will have the same conclusion that he will not execute the remaining commands when running asperascp.exe.

Any tips?

Thanks.

+5
source share
2 answers

You can use the Start / b command.

 @echo off cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\" Start "" /b asperascp.exe timeout /T 5 /nobreak >nul taskkill /IM asperascp.exe /F 
+7
source

TASKKILL /IM asperascp.exe /F
will kill all images with the same image name. Therefore, if you run the same program twice, for example, and the second starts before the first, the second will also be killed when the first runs taskkill. If you make a tasklist , you will see several images with the same image name, but with different PIDs. You will need to get the PID of the process started by your batch file (I can’t figure out how to do this with CMD.) Then you can use: TASKKILL /PID 999 /F

+3
source

Source: https://habr.com/ru/post/1245131/


All Articles