computing
  • 0

Solved Batch Script Typeperf.exe MONITOR CPU PROCESS

  • 0

MONITOR CPU PROCESS, Have been using some third party software to monitor the total overall process on my CPU this is handy but unfortunately other Anti virus software keeps flagging it as malicious software, I really want to use a script that can do this for me that will avoid these problems, I found this pice of code online from http://stackoverflow.com/questions/… according to the user who requested help it works for him but I am getting an error message can anyone here tell me what’s wrong ?

Here is my modified code below, all I have changed is adding the SET Variable to simplify setting an PROGRAMNAME.EXE to monitor.

@echo on
setlocal enabledelayedexpansion
:: ————— debug —————–
:selftst
echo ERROR TEST LOG FLAG
IF NOT %1!==/go! %0 /go 1>%~n0.log 2>&1
SHIFT

ECHO %1 %2 %3 %4 %5
:: —————————————
set xyz=PROGRAMNAME.exe

:check

for /f “skip=2 tokens=2 delims=,” %%c in (‘typeperf “\Process(%xyz%)\%% Processor Time” -sc 1’) do (
set cpu_usage=%%~c
goto :break
)

:break

echo %cpu_usage%
set cpu_usage=%cpu_usage:.=%

:: 1 is set in the front to avoid octal comparison
if 1%cpu_usage% LSS 11000000 (
goto :check_process
) else (
goto :check
)
:: sleep for 1 second
pathping 127.0.0.1 -n -q 1 -p 1000 >nul 2>&1
:check_process

QPROCESS * | find /i “%xyz%” >nul 2>&1 && (
echo process %xyz% is running
) || (
echo process %xyz% is not running
)

endlocal

Below is the DUMP of the entire script.

OUTPUT

D:\MERGE>setlocal enabledelayedexpansion

D:\MERGE>echo ERROR TEST LOG FLAG
ERROR TEST LOG FLAG

D:\MERGE>IF NOT /go! == /go! “D:\MERGE\cpumon1.bat” /go 1>cpumon1.log 2>&1

D:\MERGE>SHIFT

D:\MERGE>ECHO
ECHO is on.

D:\MERGE>set xyz=PROGRAMNAME.exe

D:\MERGE>for /F “skip=2 tokens=2 delims=,” %c in (‘typeperf “\Process(PROGRAMNAME.exe)\% Processor Time” -sc 1’) do (
set cpu_usage=%~c
goto :break
)

D:\MERGE>echo
ECHO is on.

D:\MERGE>set cpu_usage=.=
= was unexpected at this time.
D:\MERGE>if 1.= LSS 11000000 (

 

If Dreams Come True Oleg Would be Famous so far he’s very shy, so much for Being Famous 😉 http://www.book-stores.com/angels-

message edited by Ortorea

Share

1 Answer

  1. You don’t have XP home, do you? I think that’s the one main version of Windows without WMIC.

    How To Ask Questions The Smart Way

    • 0