[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程批处理在线视频分享
返回列表 发帖

[原创] VBScript监测指定进程的CPU占用率

  1. ProcessName = "ttplayer.exe"
  2. Set objSWbemService = GetObject("winmgmts:\\.\root\cimv2")
  3. set colItems = objSWbemService.ExecQuery("select * from Win32_Processor")
  4. for each objItem in colItems
  5.     CpuNum = CpuNum + objItem.NumberOfLogicalProcessors
  6. next
  7. set colItems = objSWbemService.ExecQuery("select * from Win32_Process " _
  8.     & " where Name = '" & ProcessName & "'")
  9. for each objItem in colItems
  10.     ProcessId = objItem.ProcessId
  11.     exit for
  12. next
  13. set colItems = objSWbemService.ExecQuery( _
  14.     "select * from Win32_PerfFormattedData_PerfProc_Process " _
  15.     & " where IDProcess = " & ProcessId)
  16. for each objItem in colItems
  17.     'WScript.Echo objItem.Path_.RelPath
  18.     set SWbemObject = objItem
  19. next
  20. SWbemObject.Refresh_
  21. do
  22.     SWbemObject.Refresh_
  23.     WScript.StdOut.write vbCr & Time() & vbTab _
  24.         & (SWbemObject.PercentProcessorTime / CpuNum) & "%" & vbTab
  25.     WScript.Sleep 1000
  26. loop
复制代码
一个程序可能有多个进程实例,这里只处理单进程的情况。要处理多个进程也很简单,有需要者请自行修改。
1

评分人数

    • zqz0012005: 鼓励原创作品,感谢分享PB + 10 技术 + 1
我不知道

返回列表