find PID from an SVCHOST process

Netgear / Dg834g
November 9, 2011 at 16:33:56
Specs: Windows XP SP3, 4000+ / 2gb DDR
I need help modifying some BATCH FILE code (SEE BELOW Under CODING), I occasionally have a situation arising on a computer when a SUB process running from SVCHOST.EXE uses 100% CPU, causing instability this process only runs when the computer is unstable and is not able to complete it's cycle only a chkdsk scheduling and reboot fixes the problem.

I have no idea what this is but anti-virus and antimalware scans show nothing, however this is using a lot of CPU cycles and when I force terminate the process my system tray reloads after going blank grey and everything seems to work ok again.

I have found through "HD Tune" that the HARD DRIVE has a faulty sector and i'm planning to replace this asap as this is my FTP, and voice chat - SERVER pc, I suspect it has something to do with corrupting file's on the disk cache, after running disk doctor this issue keeps on coming back usually after a day or 2.

:CODING
I need help modyfying this code to detect if this process is running but because their are several OTHER svchost processes it must be by PID (Program ID))

the code I need modifying is this:
:: ----------------------------------------------------------------------------
for /f "tokens=*" %%1 in ('tasklist /nh ^|find "%appname%"') do (
for /f "tokens=5" %%A in ("%%1") do (
set memuse=%%A
)
)
goto end

:repair
:: commands to do
:: ----------------------------------------------------------------------------


Obviously this code checks memory use someone here helped me with previously it has proven very useful but this finds a program by APP NAME what I need is to find a program if it exists by PID

Once known if the PID exists I want to have it perform a GOTO function to :DISK_REPAIR_REBOOT

I have the last commands for running a chkdsk and a reboot the only part I need help with is the find if exist for the PID if the PID=1032 for one of the svchost processes, then I want to have the GOTO activated.

Can someone help please ?

Regards, Michelle xxx


See More: find PID from an SVCHOST process

Report •


#1
November 9, 2011 at 20:14:50
Oh I think I figured it out lol was so obvious.

@echo off
setlocal enabledelayedexpansion
cls
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: **************************************************************
:: ---------------- WARNING ONLY SET UNWANTED PROCESS @ appname1
set appname1=1032
:: ---------------- ONLY SET REQUIRED RUNNING PROCESS @ appname2
set appname2=3476
:: -------------------------------------------------------------
:: 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 Comparing MEMORY USE Two = %stability2% kb *
:: -------------------------------------------------------------
sleep 30
IF "%stability1%"=="" (
echo. Test mode variable 1 is null system is OK
echo.

GoTo stable
) ELSE (
echo. Test mode variables 1 is active system is potentially not viable
Taskkill /F /PID %appname1%
echo.
)

goto checkdisk
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: **************************************************************
::
:: EXTRA FINALS BELOW
:checkdisk
echo CHECKING THE HD
pause
cls
goto end
:stable
echo ALL IS WORKING OK
pause
:end


Report •

#2
November 16, 2011 at 17:36:07
Well it did not work out as I had hoped, seems the PID is not fixed and changes, so it's back to the drawing board, I am now trying another method basically when one program starts running it has some dependencies that it loads and if these do not start up as they should then it is because it has frozen somewhere.

I include the coding so far below, the problem I have is with appname2 It needs to be able to find a SUB (child process) started by svchost.exe which it does not find any help would be much appreciated.

:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: **************************************************************
:: SET THE PROGRAM - 1st REQUIRED RUNNING PROCESS @ appname1
set appname1=mirc.exe
::
:: SET DEPENDANCYS - 2nd REQUIRED RUNNING PROCESS @ appname2
set appname2=svchost.exe(956)
:: Note the actual program is called 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
)
)

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

)
goto unattended
:: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:stable

Thanks Michelle xxxx


Report •
Related Solutions


Ask Question