如何使用Batch FIle查找CPU,RAM和内存使用的百分比

时间:2015-09-09 10:22:05

标签: cmd

我希望显示CPU使用率和可用CPU百分比, RAM和带有日期和时间戳的运行程序相同

@echo off 
Powershell -command "&{Get-WmiObject -Query 'Select * from Win32_PerfFormattedData_PerfProc_Process '| Select Name, @{Name='CPU(p)';Expression={$_.PercentProcessorTime}} | where {$_.'CPU(p)' -gt 0 } |Sort 'CPU(p)' -descending | Format-Table -AutoSize;}" 
Powershell -command "&{Get-Process | Select Name, @{Name='CPU(s)';Expression={$_.CPU}} | sort 'CPU(s)' -Descending | Select -First 5| Format-Table -AutoSize;}"
 Powershell -noexit -command "&{Get-WmiObject -Query 'Select * from Win32_OperatingSystem' | Select FreePhysicalMemory | Format-Table -AutoSize;}

我尝试了上面的代码,但我希望输出像CPU%Utilized%Free,RAM%利用%Free,程序%CPU%RAM

1 个答案:

答案 0 :(得分:0)

试试这个:

@echo off

set totalMem=
set availableMem=
set usedMem=
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%



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%

来源:How to get the current CPU usage and available memory in batch file?