How to get current CPU usage and available memory in a batch file?

Am I creating a simple script that displays the current user logging in, using CPU for the current system and available memory?

I managed to get the current user / user, but is it possible to get processor and memory usage?

This is my code so far.

@echo off for /f "tokens=3 delims=\" %%i in ("%USERPROFILE%") do (set USER=%%i) 2>&1 echo "Logged On User: %USER%" echo. pause 

To get processor usage, I tried this command but it doesn't seem to work.

 for /f "skip=1" %p in ('wmic cpu get loadpercentage') do echo %p% 
+6
source share
4 answers

You can always use the systeminfo command, but then you have to go through the short boot screen

 set totalMem= set availableMem= set usedMem= REM You need to make a loop for /f "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a) set totalMem=%totalMem:,=% set availableMem=%availableMem:,=% set /a usedMem=totalMem-availableMem Echo Total Memory: %totalMem% Echo Used Memory: %usedMem% 

And that should do exactly what you want. This code can be easily changed to display virtual memory. (Using set totalMem=%totalMem:,=% and set availableMem=%availableMem:,=% eliminates commas in variables.)

Mona

+3
source

First, when starting from a batch file, a for loop variable requires two percentage characters - %%p

Secondly, you need an echo %%p , not %p% :

 for /f "skip=1" %%p in ('wmic cpu get loadpercentage') do echo %%p 

From the command line:

 for /f "skip=1" %p in ('wmic cpu get loadpercentage') do echo %p 
+6
source
 typeperf "\processor(_Total)\% Processor Time" -SC 1 -y 

or

 C:\>logman create counter CPU_Usage3 -c "\Processor(_Total)\% Processor Time" -f csv -o %temp%\cpu.csv The command completed successfully. C:\>logman start CPU_Usage3 The command completed successfully. C:\>logman stop CPU_Usage3 The command completed successfully. C:\>type %temp%\cpu*.csv The system cannot find the file specified. 

Typeperf is not available for WindowsXP home, but logman requires administrator rights and creates a temporary file. TYPEPERF . LOGMAN . To check memory these counters are: http://ss64.com/nt/syntax-performance-counters.html

0
source
 @echo off setlocal enabledelayedexpansion set Times=0 for /f "skip=1" %%p in ('wmic cpu get loadpercentage') do ( set Cpusage!Times!=%%p set /A Times=!Times! + 1 ) echo Percentage = %Cpusage0% pause 
0
source

Source: https://habr.com/ru/post/958824/