Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: need a script to monitor CPU usage on PC  (Read 1974 times)

0 Members and 1 Guest are viewing this topic.

valyusha

  • Guest
need a script to monitor CPU usage on PC
« on: February 07, 2006, 12:52:24 PM »
Hi all,
I need to run a script to load URLs from a plain file into a browser window and monitor CPU usage on PC.
Any idea's welcome.
Thanks.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: need a script to monitor CPU usage on PC
« Reply #1 on: February 08, 2006, 06:45:36 PM »
Not very elegant, but this might work.

Code: [Select]
Set objIE = CreateObject("InternetExplorer.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const TriStateUseDefault = -2
Const ForReading = 1

strComputer = "."

Set f = fso.GetFile("c:\url.txt")            '<== Change Path to URL File
Set fs = f.OpenAsTextStream(ForReading, TriStateUseDefault)

While fs.AtEndOfStream <> True
      url = fs.Readline
      objIE.Navigate url

      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)

      For Each objItem In colItems
     WScript.Echo url & "  LoadPercentage: " & objItem.LoadPercentage
      Next
      
      While objIE.Busy = True
      Wend

Wend

objIE.Quit
fs.Close

Be sure to change the path to the URL file. URLs in the file should be in the format http://

Save the script with a VBS extension and run from the command prompt: cscript scriptname.vbs
 
Good luck.  8-)

Note: You will not see IE as it's never made visible. Also, keep in mind that the script itself will add to the CPU load.
« Last Edit: February 08, 2006, 06:57:31 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

valyusha

  • Guest
Re: need a script to monitor CPU usage on PC
« Reply #2 on: February 09, 2006, 01:03:09 PM »
Thank you :)