Board logo

标题: [系统相关] 批处理如何查询64位系统的内存、cpu使用状况? [打印本页]

作者: cupzdz    时间: 2010-12-28 16:09     标题: 批处理如何查询64位系统的内存、cpu使用状况?

@echo off
:cpu
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value^|findstr "PercentProcessorTime"')
do (
  set UseCPU=%%a
  goto :mem
)
:mem
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PhysicalMemory get * /value^|findstr "Capacity"') do (
  set TalMem=%%a
)
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Memory get * /value^|findstr "AvailableBytes"') do (
  set UseMem=%%a
)
:show
echo 当前时间: %date% %time%
echo CPU使用率:%UseCPU%
echo 物理内存总量:%TalMem%
echo 当前可用内存:%UseMem%



因为特殊需求 需要2小时记录一次内存和cpu使用情况,并且打印出来。在自己的电脑上测试上面的脚本已经没有问题,可以正常记录 ,配合计划任务可以打印到文本中。
不过需要记录的服务器是64位系统 内存8G ('wmic path Win32_PhysicalMemory get * /value^|findstr "Capacity"') 只能取到2G
不知道有哪位高手可以提醒下 帮忙修改。
谢谢!
作者: Batcher    时间: 2010-12-28 17:40

看看systeminfo命令的结果里面有没有你想要的东西
作者: andyrave    时间: 2010-12-28 17:49

  1. @echo off
  2. :cpu
  3. for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value^|findstr "PercentProcessorTime"') do (
  4. set UseCPU=%%a
  5. goto :mem
  6. )
  7. :mem
  8. for /f "tokens=1,* delims==" %%i in ('systeminfo^|find "物理内存总量"') do (
  9. for /f "tokens=1,* delims==" %%w in ('systeminfo^|find "可用的物理内存"') do (
  10. set TalMem=%%i
  11. set UseMem=%%w
  12. goto :show
  13. )
  14. )
  15. :show
  16. echo 当前时间: %date% %time%
  17. echo CPU使用率:%UseCPU%
  18. echo %TalMem%
  19. echo %UseMem%
  20. pause
复制代码

作者: cupzdz    时间: 2010-12-28 18:15

非常感谢 基本上已经解决了。。。。谢谢 谢谢




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2