Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script


@ECHO OFF
setlocal enabledelayedexpansion

::Set arrsize -1
set  arrsize=3
set  executable[0]=WINWORD
set  executable[1]=POWERPNT
set  executable[2]=EXCEL
set  executable[3]=AcroRd32

::read it using a FOR /L statement
for /l %%n in (0,1,%arrsize%) do (
CALL :IsRunning !executable[%%n]!
)
GoTo :AppEndChoice
:IsRunning
tasklist /FI "IMAGENAME eq %1.exe" 2>NUL | find /I /N "%1.exe">NUL
IF "%ERRORLEVEL%"=="0" GOTO :AppChoice
EXIT /B

:AppChoice
ECHO %1 Current Running
ECHO Kill Program to Continue (Y) or STOP (N)?
CHOICE /C YN /M "Press Y for Yes, N for No"
IF %ERRORLEVEL% EQU 1 GOTO :AppYes
IF %ERRORLEVEL% EQU 2 GOTO :AppNo
:AppYes
tskill %1
GoTo:AppEndChoice
:AppNo
EXIT
:AppEndChoice
EXIT /B
  • No labels