|
|
Title | Learn the number of CPUs on the system |
Description | This example shows how to learn the number of CPUs on the system in Visual Basic 6. |
Keywords | CPUs, number CPUs, CPU, processors |
Categories | Windows, Software Engineering |
|
|
Thanks to Thorsten Zeimantz (Zeimantz@FIS.LU) and Hans-Otto Langguth (h.o.langguth@gmx.de) for each telling me about this technique. This example was adapted from the German site VB-fun.de.
The GetCPUData function uses Windows Management Instrumentation (WMI) to get information about the system's processors.
|
|
' Adapted from:
' http://www.vb-fun.de/cgi-bin/loadframe.pl?ID=vb/tipps/tip0477.shtml
Private Function GetCPUData() As String
Dim result As String
Dim objCPUItem As Object
Dim objCPU As Object
On Error Resume Next
Set objCPUItem = _
GetObject("winmgmts:").InstancesOf("Win32_Processor")
If Err.Number <> 0 Then
result = "Error getting Win32_Processor " & _
"information." & vbCrLf
Else
result = "Number of processors incl. Co-CPUs: " & _
Trim$(Str$(objCPUItem.Count)) & vbCrLf & vbCrLf
For Each objCPU In objCPUItem
result = result & "Processor: " & _
objCPU.DeviceID & vbCrLf
result = result & "Description: " & _
Trim$(objCPU.Name) & vbCrLf
result = result & "Frequency (MHz): " & _
objCPU.MaxClockSpeed & vbCrLf
result = result & "CPU-ID: " & _
objCPU.ProcessorId & vbCrLf
result = result & vbCrLf
Next
Set objCPUItem = Nothing
End If
GetCPUData = result
End Function
|
|
|
|
|
|