Solved Find a SUB Process P.I.D. WITH a Batch file

Netgear / Dg834g
November 16, 2011 at 19:15:55
Specs: Windows XP SP3, 4000+ / 2gb DDR
I need help in my batch file to find a SUB PROCESS at my "CHECKING TWO" portion of the batch file, I can use this to find top level processes but if it was started via another process such as SVCHOST.EXE then I cannot find it

Can anyone help please ?

:: BEGIN SAMPLE OF BATCH FILE
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: **************************************************************
:: SET THE PROGRAM - 1st REQUIRED RUNNING PROCESS @ appname1
set appname1=mirc.exe
::
:: SET DEPENDANCYS - 2nd REQUIRED RUNNING PROCESS @ appname2
set appname2=svchost.exe(956)
:: REQUIRED set appname2=AgentSvr.exe
:: Note the actual program is called AgentSvr.exe (THE PID CHANGES EVERY TIME IT IS RUN)

:: -------------------------------------------------------------
:: CHECKING ONE
for /f "tokens=*" %%1 in ('tasklist /nh ^|find "%appname1%"') do (
for /f "tokens=5" %%A in ("%%1") do (
set stability1=%%A
)
)

sleep 3
cls
:: -------------------------------------------------------------
:: CHECKING TWO
for /f "tokens=*" %%1 in ('tasklist /nh ^|find "%appname2%"') do (
for /f "tokens=5" %%A in ("%%1") do (
set stability2=%%A
)
)

echo MEMORY USE One = %stability1% kb
echo Comparing MEMORY USE Two = %stability2% kb
:: -------------------------------------------------------------
IF "%stability1%"=="" (
echo.
echo. Test mode variable 1 is NULL %appname1% is NOT RUNNING
echo.
sleep 15
cls
GoTo stable
) ELSE (
echo. Test mode variable 1 is active will check for
echo. %appname2% activation PLUS %appname1%
IF "%stability2%"=="" goto stable1
goto stable
:stable1
echo. It Appears that %stability2% is not running.
sleep 6
cls
IF NOT "%stability1%"=="" goto unattended

)

:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:stable
:: END SAMPLE OF BATCH FILE


Thanks Michelle xxx


See More: Find a SUB Process P.I.D. WITH a Batch file

Report •


#1
November 16, 2011 at 21:48:07
✔ Best Answer
This should be in the Programming Forum here: http://www.computing.net/forum/prog...

Report •

#2
November 17, 2011 at 02:39:29
ahh, Ewen I am not sure where it ended up, also I found out what was wrong it was a silly CaPital letter problem DOH it works now windows drives me batty sometimes it displays the name with a Capital in process explorer yet in TASKLIST its all lower case....

Anyways its working now thanks.

Michelle xxxx


Report •

#3
November 17, 2011 at 04:26:54
Here is my new code sample it does work now, Basically it is meant to check that dependencies required by the first program are working (THE SECOND) if not then it carries out a pre-determined action.

@echo off
if not exist sleep.com echo you do not have sleep.com && pause && goto end
setlocal enabledelayedexpansion
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
set flag1=YES && set flag2=YES
set state="C:\state\status.txt"
:: **************************************************************
:: BOTH APPLICATIONS MUST BE RUNNING FOR PC TO BE CONSIDERED OK
:: IF APPLICATION appname1 IS NOT running appname2 status is ignored.
:: ---------- SET REQUIRED RUNNING PROCESS @ appname1 -----------
set appname1=mirc.exe
:: ---------- SET REQUIRED RUNNING PROCESS @ appname2 -----------
set appname2=agentsvr.exe
:: -------------------------------------------------------------
:: CHECKING ONE
for /f "tokens=*" %%1 in ('tasklist /nh ^|find "%appname1%"') do (
for /f "tokens=5" %%A in ("%%1") do (
set stability1=%%A
)
)

sleep 3
cls
:: -------------------------------------------------------------
:: CHECKING TWO
for /f "tokens=*" %%1 in ('tasklist /nh ^|find "%appname2%"') do (
for /f "tokens=5" %%A in ("%%1") do (
set stability2=%%A
)
)

IF "%stability1%"=="" set flag1=NO
IF "%stability2%"=="" set flag2=NO
sleep 10
cls
echo --------------------------------------------------------------
echo Are the following programs running ?
echo.
echo. %appname1% Running ? %flag1% @ T: %time% D: %date%
echo. %appname2% Running ? %flag2% @ T: %time% D: %date%
echo.
echo --------------------------------------------------------------
>> %state% echo IS %appname1% Running ? %flag1% @ T: %time% D: %date%
>> %state% echo IS %appname2% Running ? %flag2% @ T: %time% D: %date%
>> %state% echo ---------------------------------------------------
:: ----------------------------------------------------------------
sleep 10
cls
::
IF "%stability1%"=="" (
echo.
echo. Test mode variable 1 is NULL %appname1% is NOT RUNNING Nothing to Compare
echo.
sleep 15
cls
GoTo stable1
) ELSE (
echo. Test mode variable 1 is active will check for
echo. %appname2% activation PLUS %appname1%
IF "%stability2%"=="" goto stable1
goto done
:stable1
echo. It Appears that %appname2% is not running.
sleep 6
cls
IF NOT "%stability1%"=="" goto unattended
echo.
)

goto done
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

:: END

:unattended
echo do something drastic like run a dialogue warning or a fix process script
goto end

:done
cls

:end
cls
endlocal


Report •

Related Solutions

#4
November 17, 2011 at 15:11:27
Thanks for responding... glad it worked out.

Report •


Ask Question