I am creating a simple script that outputs the current user logged in, CPU usage for the current system and the available memory?
I have managed to get the current user/s logged on but is it possible to get the cpu usage and memory as well?
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 the cpu usage i have tried this command but it doesn't seem to be working.
for /f "skip=1" %p in ('wmic cpu get loadpercentage') do
echo %p%
Firstly, when running from a batch file, the for loop variable needs two percentage symbols - %%p
Secondly, you need to 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With