How can I recognize a running batch file in task manager?

16,157

open Task Manager, click on the Processes tab, and select View->Select Columns.... Turn the checkbox Command Line on. Now Task Manager will show you, for each cmd.exe, what it is running. For a batch file this looks like

cmd /c ""C:\path\to\test.bat""

For your question on making sure only a single instane can run, this rather dirty trick works:

@echo off

tasklist /v | find /I /c "MyUniqueTitle" > nul
if "%ERRORLEVEL%" == "0" goto ErrorAlreadyRunning

title MyUniqueTitle
echo "Running as Single Instance!"
goto end


:ErrorAlreadyRunning
echo "ErrorAlreadyRunning"

:end
pause
Share:
16,157

Related videos on Youtube

Nime Cloud
Author by

Nime Cloud

Updated on September 18, 2022

Comments

  • Nime Cloud
    Nime Cloud over 1 year

    I run a few batch files as SYSTEM (as services) and they appear as cmd.exe in tasklist. Sometimes I need to terminate one of them but I cannot decide which cmd.exe to terminate.

    Plus; I run many batch files as scheduled tasks, all appear as cmd.exe (with my account)

    How can I mark a batch file, so I can recognize it at task manager?

  • stijn
    stijn over 12 years
    oops seems you removed the single instance question already :]
  • Nime Cloud
    Nime Cloud over 12 years
    That "MyUniqueTitle" label may work...
  • David Gleba
    David Gleba over 3 years
    It takes about 10 seconds to get the tasklist on my pc. In that time, a second instance could start.