Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLearn the number of CPUs on the system
DescriptionThis example shows how to learn the number of CPUs on the system in Visual Basic 6.
KeywordsCPUs, number CPUs, CPU, processors
CategoriesWindows, 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
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated