Is there a way to do this purely in a .bat file?
The purpose is to launch iexplore.exe
, then kill just that instance when it's finished.
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort.
A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system. The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
Use the Command PromptIn the Start menu search bar, search for command prompt and select Run as administrator. Type tasklist. Press Enter. Command Prompt will now display the PID for the running processes.
$ expands to the process ID of the shell. So, you can see the PID of the current shell with echo $$ . See the Special Paramaters section of man bash for more details.
Here's what I use:
@echo off
rem there is a tab in the file at the end of the line below
set tab=
set cmd=javaw -jar lib\MyProg.jar
set dir=%~dp0
echo Starting MyProg
set pid=notfound
for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
`wmic process call create "%cmd%"^, "%dir%"`
) do (
if /I %%i EQU ProcessId (
set pid=%%j
)
)
echo %pid% > MyProg.pid
The directory is set to the directory that the cmd file is located in. Change dir
to alter that. Modify cmd
to change which command is run.
If you want a stop.cmd that kills it, it would look like this
@echo off
for /F %%i in (%~dsp0MyProg.pid) do taskkill /F /PID %%i
del %~dsp0MyProg.pid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With