欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

查看CPU使用率

程序员文章站 2022-03-16 23:44:27
参考 ......
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