' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' // © 1999-2004, ActiveXperts Software B.V.
' //
' // For more information about ActiveXperts Network Monitor and VBScript, please
' // visit the online ActiveXperts Network Monitor VBScript Guidelines at:
' //    http://www.activexperts.com/support/activmonitor/online/vbscript/
' // 
' ///////////////////////////////////////////////////////////////////////////////
'  

Option Explicit

Dim strComputer

Do
  strComputer = inputbox( "Enter the name ofthe (remote) computer", "Computer", "localhost" )
Loop until strComputer <> ""

While 1 = 1
  CheckCpuUsage strComputer 
  WScript.Sleep 1000
WEnd


' //////////////////////////////////////////////////////////////////////////////

Sub CheckCpuUsage( strComputer ) 

On Error Resume next

    Dim objWMIService, nCpuUsage 
    Dim collCPUs, objCPU


    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
    If( Err.Number <> 0 ) Then
        WScript.Echo "Unable to connect to WMI service on computer [" & strComputer & "]. Possible reasons: remote computer is down, has no WMI installed, or requires other credentials to access WMI"
        Exit Sub 
    End If

    set collCPUs = objWMIService.ExecQuery( "select * from Win32_Processor" ) 
    If( collCPUs.Count = 0 ) Then
        WScript.Echo "Unable to list processors on computer [" & strComputer & "]"
        Exit Sub			    
    End If

    For Each objCPU in collCPUs
      If( Err.Number <> 0 ) Then
          WScript.Echo "Unable to list processors on computer [" & strComputer & "]"
          Exit Sub 
      End If

      nCpuUsage  = objCPU.LoadPercentage    
      WScript.Echo objCPU.DeviceID & " usage=[" & nCpuUsage & "%]"
    Next

End Sub



