查看CPU使用率

rem 如果wmi服务(服务名为Winmgmt)坏掉了,需要到system32\webm目录下执行如下注释的命令

rem for %i in (*.dll) do RegSvr32 -s %i
rem Regsvr32 -s scrcons.exe
rem Regsvr32 -s unsecapp.exe
rem Regsvr32 -s wbemtest.exe
rem Regsvr32 -s WinMgmt.exe
rem Regsvr32 -s WmiApSrv.exe
rem Regsvr32 -s WmiPrvSE.exe

@echo off
@echo On Error Resume Next>temp.vbs
@echo.>>temp.vbs
@echo dim iCpuUsePercentage>>temp.vbs
@echo dim objFileStream>>temp.vbs
@echo dim objTextFileWriter>>temp.vbs
@echo Set objProc = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")>>temp.vbs
@echo iCpuUsePercentage=objProc.LoadPercentage>>temp.vbs
@echo set objFileStream =CreateObject("Scripting.Filesystemobject")>>temp.vbs
@echo set objTextFileWriter=objFileStream.opentextfile("log.tmp",8,True)>>temp.vbs
@echo objTextFileWriter.WriteLine(iCpuUsePercentage)>>temp.vbs
@echo objTextFileWriter.close>>temp.vbs
start temp.vbs
ping -n 3 127.0.0.1 >nul
del %~dp0temp.vbs
@echo CPU占用率:
type log.tmp
pause
del %~dp0log.tmp

 

使用wmic记录CPU使用率,每隔一秒记录一次,记录到日志中。并打印出对应的时间。将批处理内容保存为.bat文件执行即可。其中的执行次数1000000可以自行修改,比如运行24小时的话,可以修改为24*3600.

@echo off
set log=%~dp0cpu%date%.log
for /L %%i in (0,1,1000000) do (
wmic os get localdatetime /value>>%log%
wmic cpu get loadpercentage /value /every:1 /repeat:1>>%log%
)

 

网络速率检测 

@echo off

set log="%~dp0network%date%.log"

for /F "tokens=2" %%i in ('netstat -e ^| find "字节"') do set down1=%%i
for /F "tokens=3" %%i in ('netstat -e ^| find "字节"') do set up1=%%i
:run
for /F "tokens=2" %%i in ('netstat -e ^| find "字节"') do set /A down=( (%%i-%down1%) /1024 )  & set down1=%%i
for /F "tokens=3" %%i in ('netstat -e ^| find "字节"') do set /a up= ( ( %%i-%up1% ) /1024 ) & set up1=%%i
echo -------------->>%log%
echo %date% %time% Down %down% KB  Up %up% KB >>%log%
ping 127.0.0.1 -n 2 >nul
title %down% KB Down %up% KB Up
goto:run

 

 

 C#写的系统资源监控程序,不错

收藏地址

CodeProject上的一个例子

参考

你可能感兴趣的:(查看CPU使用率)