|
-
Apr 28th, 2013, 04:10 AM
#16
Re: Cpu Utilization in vb6
Using my WMI Browser (http://www.vbforums.com/showthread.p...ser&highlight=) on a Dual Core, 4 Logical Processor machine the _ProcessorInformation query returns 6 records:
Record 1 'Name' Property = _Total
Record 2 'Name' Property = 0,_Total
Record 3 'Name' Property = 0,3
Record 4 'Name' Property = 0,2
Record 5 'Name' Property = 0,1
Record 6 'Name 'Property = 0,0
I'd guess that only record 1 (or perhaps 2) are actually required. Adding all 6 up and taking the average will not be correct (if I interpret MS's use of the word "Total" correctly)
Just for fun, I tried 4 methods and unsurprisingly, got 4 different results.
Code:
Private wmi As Object
Private Sub Form_Load()
Me.Show
Set wmi = GetObject("winmgmts:\\.\root\CIMV2")
Timer1.Interval = 500
Timer1_Timer
End Sub
Private Sub Timer1_Timer()
Dim query As Object, query1 As Object, counter As Object
Dim percent As Double
Set query = wmi.ExecQuery("SELECT * FROM Win32_PerfFormattedData_Counters_ProcessorInformation")
Set query1 = wmi.ExecQuery("Select * from Win32_Processor")
For Each counter In query
Select Case counter.Name
Case "_Total"
Text1.Text = "_Total: " & Format(counter.percentprocessortime, "0.00") & "%"
Case "0,_Total"
Text2.Text = "0,_Total: " & Format(counter.percentprocessortime, "0.00") & "%"
Case Else
percent = percent + counter.percentprocessortime
End Select
Next
Text3.Text = "Average of " & CStr(query.Count) & " records: " & Format(percent / query.Count, "0.00") & "%"
percent = 0
For Each counter In query1
percent = percent + counter.LoadPercentage
Text4.Text = "LoadPercentage(" & counter.numberoflogicalprocessors & "LPs): " & Format(percent, "0.00") & "%"
Next
End Sub
@Bonnie: You may like to run the WMI Browser and see if you can find (in the CIMV2 Namespace) the Classes. I know that some classes have been 'moved about' by MS with various Versions of Windows.
You should find the Win32_Processor class in:
CIM_Managed_System_Element -> CIM_LogicalDevice -> CIM_Processor
The LoadPercentage property is an unsigned 16 bit integer.
The Win32_PerfFormattedData_Counters_ProcessorInformation class should be found in
CIM_StatisticalInformation -> Win32_Perf -> Win32_PerfFormattedData
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|