Determine CPU usage percentage in windows xp

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Determine CPU usage percentage in windows xp

#1 Post by mohdfraz » 09 Dec 2013 10:19

Hi,

Is there any way to Determine CPU usage percentage in windows xp and if CPU running below 40% then do this task?

Thanks

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: Determine CPU usage percentage in windows xp

#2 Post by princesstwi » 09 Dec 2013 10:21

look in task manager for usage but as for the batch file im not sure :)

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Determine CPU usage percentage in windows xp

#3 Post by Ed Dyreen » 09 Dec 2013 15:26

One way to retrieve the number of processors is using WMIC eg;

Code: Select all

path WIN32_PROCESSOR get NumberOfLogicalProcessors.
A way to retrieve CPU load is typeperf.EXE eg;

Code: Select all

for %%? in ( be, nl ) do if /i "!§lang!" == "%%~?" set "$cmd=Percentage processortijd"
for %%? in ( us, uk ) do if /i "!§lang!" == "%%~?" set "$cmd=Processor Time"
total;

Code: Select all

'typeperf.EXE "\Proces(*)\!$cmd!" -sc 1'
or per process;

Code: Select all

'typeperf.EXE "\Proces(^!$p^!)\!$cmd!" -sc 1'
and divide the load ( typeperf ) by numOfCores;

Code: Select all

set /a $cpu = $typeperf / $cores
These are XP native.

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Determine CPU usage percentage in windows xp

#4 Post by mohdfraz » 10 Dec 2013 03:26

Ed Dyreen wrote:One way to retrieve the number of processors is using WMIC eg;

Code: Select all

path WIN32_PROCESSOR get NumberOfLogicalProcessors.
A way to retrieve CPU load is typeperf.EXE eg;

Code: Select all

for %%? in ( be, nl ) do if /i "!§lang!" == "%%~?" set "$cmd=Percentage processortijd"
for %%? in ( us, uk ) do if /i "!§lang!" == "%%~?" set "$cmd=Processor Time"
total;

Code: Select all

'typeperf.EXE "\Proces(*)\!$cmd!" -sc 1'
or per process;

Code: Select all

'typeperf.EXE "\Proces(^!$p^!)\!$cmd!" -sc 1'
and divide the load ( typeperf ) by numOfCores;

Code: Select all

set /a $cpu = $typeperf / $cores
These are XP native.


Ed Dyreen,
Thank you for your reply. The code you gave me are not working. I used this code below code and it work and writes CPU usage percentage to csv file. Now i need a way that this code monitor CPU usage for 6 times and if at any of the time CPU usage is below 50% then run command A other wise Run command B. Could you please tell me how to do this...

Code: Select all

typeperf "\processor(_Total)\% Processor Time" -O C:\SS64demo1.csv -SC 6


Awaiting

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Determine CPU usage percentage in windows xp

#5 Post by mohdfraz » 11 Dec 2013 06:30

Is there Any body who can solve this,,,,,,,,,

I need a way that this below code monitor CPU usage for 6 times and if at any of the time CPU usage is below 50% then run command A other wise Run command B.

Code: Select all

typeperf "\processor(_Total)\% Processor Time" -O C:\SS64demo1.csv -SC 6


Awaiting

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Determine CPU usage percentage in windows xp

#6 Post by foxidrive » 11 Dec 2013 06:40

See if this floats your boat:

Code: Select all

@echo off
set "cpu="
for /f "skip=1" %%a in ('wmic cpu get loadpercentage') do if not defined cpu set "cpu=%%a"
if %cpu% GTR 50 (
   call batchA
 ) else (
   call batchB
)
pause

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Determine CPU usage percentage in windows xp

#7 Post by mohdfraz » 11 Dec 2013 06:49

foxidrive wrote:See if this floats your boat:

Code: Select all

@echo off
set "cpu="
for /f "skip=1" %%a in ('wmic cpu get loadpercentage') do if not defined cpu set "cpu=%%a"
if %cpu% GTR 50 (
   call batchA
 ) else (
   call batchB
)
pause


Foxidrive,,, You are great,,,,,,,,,,,,,,,,,, It worked like a charm,,,,, I thought it is not possible in dos but you did it.

Many thanks :)

Post Reply