'Alan dot Kaplan at va dot gov '12-20-09 'This is an expanded version of the code found at: 'http://blogs.technet.com/heyscriptingguy/archive/2005/04/21/why-does-my-performance-monitoring-script-keep-returning-the-same-incorrect-values.aspx dim wshShell Set wshShell = WScript.CreateObject("WScript.Shell") iRepeat = 5 If MYOSVer > 5.2 Then MsgBox "This requires Microsoft.CmdLib in XP and 2003 only, quitting",vbCritical + vbokonly,"Unsupported OS" WScript.Quit End If If (Not IsCScript()) Then 'If not CScript, re-run with cscript... dim quote, strArgs, i quote=chr(34) For i = WScript.Arguments.Count -1 to 0 Step -1 strArgs = WScript.Arguments(i) & Space(1) & strArgs Next WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote & space(1) & strArgs, 1, true WScript.Quit '...and stop running as WScript End If strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") If WScript.Arguments.Count = 1 Then strComputer = WScript.Arguments(0) Else strComputer = InputBox("Check Processes on what computer?","Processes",strComputer) If strComputer = "" Then WScript.Quit iRepeat = InputBox("Repeat query how many times:","Repeat",iRepeat) If irepeat = "" Then WScript.Quit End If strComputer = UCase(strComputer) 'Output formatting from 'http://technet.microsoft.com/en-us/magazine/2008.06.heyscriptingguy.aspx?pr=blog Set objCmdLib = CreateObject("Microsoft.CmdLib") Set objCmdLib.ScriptingHost = WScript.Application arrHeader = Array("Process", "Percent") arrMaxLength = Array(12, 12) strFormat = "Table" blnPrintHeader = True arrBlnHide = Array(False, False) On Error Resume Next Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") If Err.Number <> 0 Then MsgBox "Error reaching or connecting to " & strComputer, vbcritical + vbinformation,"Failure" WScript.Quit End If Set objRefresher = CreateObject("WbemScripting.SWbemRefresher") Set colItems = objRefresher.AddEnum (oWMI, "Win32_PerfFormattedData_PerfProc_Process").objectSet If Err <> 0 Then MsgBox "WMI Failure. " & Err.Description,vbCritical + vbOKOnly,"Error" WScript.Quit End If objRefresher.Refresh WScript.Echo "Beginning data collection of non-zero CPU processes on " & strComputer For i = 1 to iRepeat ReDim arrResultsArray(0) Wscript.Echo VbCrLf & "Pausing 5 Seconds..." & VbCrLf Wscript.Sleep 5000 objRefresher.Refresh iTotal = 0 iCount = 1 message = "" For Each objItem in colItems If objItem.PercentProcessorTime > 0 And objItem.Name <> "Idle" and objItem.Name <> "_Total" Then iTotal = iTotal + objItem.PercentProcessorTime ReDim Preserve arrResultsArray(iCount) arrResultsArray(iCount) = Array(objItem.Name,objItem.PercentProcessorTime ) iCount = iCount + 1 End If Next If iTotal < 100 Then arrResultsArray(0) = Array("Idle",100 - iTotal ) End If objCmdLib.ShowResults arrHeader, arrResultsArray, arrMaxLength, strFormat, blnPrintHeader, arrBlnHide Next WScript.Echo VbCrLf & "Done" Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function Function MYOSVer() Const SPKey = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion" MyOSVER = WshShell.RegRead (SPkey) End Function