getting processor id

  • 15 years ago

    I am quite new to and want to get the processor id of the pc but i am not getting any easy solution to this.

    I have found the following code on this site but unable to use to it.
    I want to use the code in form load event.
    the post was as below,but it is beyond my senses

    Private asCpuPaths() As String
    Private mobjCPUSet As SWbemObjectSet
    Private m
    objWMINameSpace As SWbemServices
    Option Explicit

    Private Sub cmdDone_Click()
    Unload Me
    End Sub

    Private Sub Form_Load()

    Dim oCpu As SWbemObject 'WMI Object, in this case, local CPUs
    Dim sPath As String, sCaption As String

    Dim lElement As Long
    ReDim asCpuPaths(0) As String

    On Error GoTo ErrorHandler

    'Get Default NameSpace, which will be the one for the local machine
    Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    Set m_objWMINameSpace = GetObject("winmgmts:")

    'Get CPU set

    Set mobjCPUSet = mobjWMINameSpace.InstancesOf("Win32Processor")
    sCaption = m
    objCPUSet.Count & " processor"
    If mobjCPUSet.Count <> 1 Then sCaption = sCaption & "s"
    sCaption = sCaption & " detected on this machine"
    lblTitle.Caption = sCaption
    'Populate list box with CPU names
    For Each oCpu In m
       With oCpu
          sPath = .Path_ & ""
              If sPath <> "" Then
                  lstCPU.AddItem .Name
                  'save path to array, so on machines with multiple CPUs,
                  'each can be identified and their info loaded into text box
                  lElement = IIf(asCpuPaths(0) = "", 0, UBound(asCpuPaths) + 1)
                  ReDim Preserve asCpuPaths(lElement) As String
                  asCpuPaths(lElement) = sPath
              End If
       End With
    If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0

    Set oCpu = Nothing

    Exit Sub

    MsgBox "CPU Information could not be displayed due to the following error: " & Err.Description, , "WMI Demo Failed"
    GoTo CleanUp
    End Sub

    Private Sub FormUnload(Cancel As Integer)
    Set m
    objCPUSet = Nothing
    Set m_objWMINameSpace = Nothing
    End Sub

    Private Sub lstCPUClick()
    Dim oCpu As SWbemObject
    'Refer to SDK documentation for more detail about each of these properties
    Dim sInfoString As String
    On Error Resume Next
    Set oCpu = m
    With oCpu
      sInfoString = "Description: " & .Description & vbCrLf
      sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
      sInfoString = sInfoString & "Status: " & .Status & vbCrLf
      sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
      sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
      sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
      sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
      sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
      sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
      sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
      sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported
    End With
    txtCpu.Text = sInfoString

    End Sub
    'Conversions from code to string were developed
    'based on information in WMI SDK documentation
    Private Function AvailabilityToString(Code As Integer) As String
    Dim sAns As String

    Select Case Code
      Case 1, 2
          sAns = "Unknown"
      Case 3
          sAns = "Running/Full Power"
      Case 4
          sAns = "Warning"
      Case 5
          sAns = "In Test"
      Case 6
          sAns = "Not Applicable"
      Case 7
          sAns = "Power Off"
      Case 8
          sAns = "Off Line"
      Case 9
          sAns = "Off Duty"
      Case 10
          sAns = "Degraded"
      Case 11
          sAns = "Not Installed"
      Case 12
          sAns = "Install Error"
      Case 13
          sAns = "Power Save - Unknown"
      Case 14
          sAns = "Power Save - Low Power Mode"
      Case 15
          sAns = "Power Save - Standby"
      Case 16
          sAns = "Power Cycle"
      Case 17
          sAns = "Power Save - Warning"
      Case Else
          sAns = "Unknown"
    End Select
    AvailabilityToString = sAns

    End Function

  • 15 years ago

    do u know vb6?  cuz thats vb6 code if im not mistaken.  which is pretty different from  there is an upgrade wizard however in visual studio that u can use to try to upgrade the vb6 code.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon