Amits Posted December 27, 2007 Posted December 27, 2007 I am working to get the CPU Usage for WinPE 2.1 . First i tried it through wmi using the below method set oSvc = GetObject("winmgmts:root\cimv2")wqlQuery = "select LoadPercentage from Win32_Processor where DeviceID = 'CPU0'"for each oData in oSvc.ExecQuery(wqlQuery)for each oProperty in oData.Properties_if oProperty.Name = "LoadPercentage" thenproc0Load = oProperty.Valueend ifnextnextwscript.echo Time() & "," & proc0Load & ","It is working for all OS except WinPE and Vista as i have seen in wbemtest the Load Percentage value is coming there as NULL.After that i tried to get the CPU usage using Performance Counters.The CPU usage counter is of type PERF_100NSEC_TIMER_INV which has the following calculation:100*(1-(X1-X0)/(Y1-Y0)) X - CounterData Y - 100NsTime Time base - 100Nswhere the denominator (Y) represents the total elapsed time of the sample interval and the numerator (X) represents the time during the interval when the monitored components were inactive.CCpuUsage class has a method called GetCpuUsage which runs through the performance objects and counters and retrieves the CPU usage. Since the CPU usage can be determined by two samplings, the first call to GetCpuUsage() returns 0, and all calls thereafter returns the CPU usage.But here also i am not getting the correct CPU Usage. It is showing as 0 and then jumping to 100 directly for WinPE2.1 May be the Performance counters are not supported in Vista and WinPE.Please guide me if i am correct in my approach till now.If not, please provide me the way to get the CPU Usage in WINPE 2.1 version.Waiting for the quick reply.Thanks in advance.
Amits Posted January 11, 2008 Author Posted January 11, 2008 Please provide your response if any body have some knowledge about the topic. Its urget.
gadget Posted January 11, 2008 Posted January 11, 2008 Sorry, it works for me.On Error Resume NextConst wbemFlagReturnImmediately = &h10Const wbemFlagForwardOnly = &h20arrComputers = Array(".")For Each strComputer In arrComputers WScript.Echo WScript.Echo "==========================================" WScript.Echo "Computer: " & strComputer WScript.Echo "==========================================" 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 "LoadPercentage: " & objItem.LoadPercentage WScript.Echo NextNextFunction WMIDateStringToDate(dtmDate)WScript.Echo dtm: WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _ Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _ & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))End Function
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now