Results 1 to 7 of 7

Thread: CPU Serial Number...

  1. #1
    AnT
    Guest

    CPU Serial Number...

    Is there a way to get the ID # of the CPU, much like you would of the HDrive, in VB?

  2. #2
    AnT
    Guest
    *bump*

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
    2.  
    3. Private Sub GetVolume(PathName As String, DrvVolumeName As String, DrvSerialNo As String)  
    4.    Dim r As Long
    5.    Dim pos As Integer
    6.    Dim hword As Long
    7.    Dim HiHexStr As String
    8.    Dim lword As Long
    9.    Dim LoHexStr As String
    10.    Dim VolumeSN As Long
    11.    Dim MaxFNLen As Long
    12.    Dim UnusedStr As String
    13.    Dim UnusedVal1 As Long
    14.    Dim UnusedVal2 As Long
    15.   'pad the strings
    16.    DrvVolumeName$ = Space$(14)
    17.    UnusedStr$ = Space$(32)
    18.   'do what it says
    19.    r = GetVolumeInformation(PathName, DrvVolumeName, Len(DrvVolumeName), VolumeSN&, UnusedVal1, UnusedVal2, UnusedStr, Len(UnusedStr$))
    20.   'error check
    21.    If r& = 0 Then Exit Sub
    22.   'determine the volume label
    23.    pos = InStr(DrvVolumeName, Chr$(0))
    24.    If pos Then DrvVolumeName = Left$(DrvVolumeName, pos - 1)
    25.    If Len(Trim$(DrvVolumeName)) = 0 Then DrvVolumeName = "(no label)"
    26.    hword = HiWord(VolumeSN)
    27.    lword = LoWord(VolumeSN)
    28.    HiHexStr = Format$(Hex(hword), "0000")
    29.    LoHexStr = Format$(Hex(lword), "0000")
    30.    DrvSerialNo = HiHexStr & "-" & LoHexStr
    31. End Sub
    32.  
    33. Private Function HiWord(dw As Long) As Integer  
    34.     HiWord = (dw And &HFFFF0000) \ &H10000
    35. End Function
    36.  
    37. Private Function LoWord(dw As Long) As Integer  
    38.     If dw And &H8000& Then
    39.         LoWord = dw Or &HFFFF0000
    40.     Else
    41.         LoWord = dw And &HFFFF&
    42.     End If    
    43. End Function
    44.  
    45. Private Sub Command1_Click()
    46. 'To Display The Volume Name And Serial Number:
    47. Dim PathName As String
    48.    Dim DrvVolumeName As String
    49.    Dim DrvSerialNo As String
    50.    PathName$ = "c:\"
    51.    GetVolume PathName, DrvVolumeName, DrvSerialNo
    52.    MsgBox "Drive Statistics for " & UCase$(PathName) & ": " & "Volume Label " & DrvVolumeName & ", " & "Volume Serial No " & DrvSerialNo
    53. End Sub

  4. #4
    AnT
    Guest
    No no no, CPU serial num, not hd

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    This is the best I could find, but I don't think it has what you want. If you found anything, post it.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    It would help if I included the link

    http://www.mvps.org/vbnet/index.html...systeminfo.htm

  7. #7
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    This Question has come up twice today!

    Here's some code from http://www.freevbcode.com/ShowCode.Asp?ID=1576

    VB Code:
    1. '***********************************************************\
    2. 'NOTES:
    3.  
    4. 'YOU MUST HAVE WMI SDK INSTALLED.  YOU CAN GET IT AT
    5. 'http://msdn.microsoft.com/downloads/sdks/wmi/default.asp
    6. 'Remember to add it in Project References!
    7. '***********************************************************************
    8.  
    9. Private asCpuPaths() As String
    10. Private m_objCPUSet As SWbemObjectSet
    11. Private m_objWMINameSpace As SWbemServices
    12. Option Explicit
    13.  
    14. Private Sub cmdDone_Click()
    15. Unload Me
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.  
    20.  
    21. Dim oCpu As SWbemObject 'WMI Object, in this case, local CPUs
    22. Dim sPath As String, sCaption As String
    23.  
    24. Dim lElement As Long
    25. ReDim asCpuPaths(0) As String
    26.  
    27.  
    28. On Error GoTo ErrorHandler
    29.  
    30. 'Get Default NameSpace, which will be the one for the local machine
    31. Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
    32. Set m_objWMINameSpace = GetObject("winmgmts:")
    33. lstCPU.Clear
    34.  
    35.  
    36. 'Get CPU set
    37.  
    38. Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
    39. sCaption = m_objCPUSet.Count & " processor"
    40. If m_objCPUSet.Count <> 1 Then sCaption = sCaption & "s"
    41. sCaption = sCaption & " detected on this machine"
    42. lblTitle.Caption = sCaption
    43. 'Populate list box with CPU names
    44.                
    45. For Each oCpu In m_objCPUSet
    46.      With oCpu
    47.         sPath = .Path_ & ""
    48.             If sPath <> "" Then
    49.                 lstCPU.AddItem .Name
    50.                 'save path to array, so on machines with multiple CPUs,
    51.                 'each can be identified and their info loaded into text box
    52.                
    53.                 lElement = IIf(asCpuPaths(0) = "", 0, UBound(asCpuPaths) + 1)
    54.                 ReDim Preserve asCpuPaths(lElement) As String
    55.                 asCpuPaths(lElement) = sPath
    56.             End If
    57.      End With
    58. Next
    59. If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0
    60.      
    61.  
    62.  
    63.  
    64.  
    65. CleanUp:
    66. Set oCpu = Nothing
    67.  
    68. Exit Sub
    69.  
    70. ErrorHandler:
    71. MsgBox "CPU Information could not be displayed due to the following error: " & Err.Description, , "WMI Demo Failed"
    72. GoTo CleanUp
    73. End Sub
    74.  
    75. Private Sub Form_Unload(Cancel As Integer)
    76. Set m_objCPUSet = Nothing
    77. Set m_objWMINameSpace = Nothing
    78. End Sub
    79.  
    80. Private Sub lstCPU_Click()
    81. Dim oCpu As SWbemObject
    82. 'Refer to SDK documentation for more detail about each of these properties
    83. Dim sInfoString As String
    84. On Error Resume Next
    85. Set oCpu = m_objCPUSet(asCpuPaths(lstCPU.ListIndex))
    86. With oCpu
    87.     sInfoString = "Description: " & .Description & vbCrLf
    88.     sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
    89.     sInfoString = sInfoString & "Status: " & .Status & vbCrLf
    90.     sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
    91.     sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
    92.     sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
    93.     sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
    94.     sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
    95.     sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
    96.     sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
    97.     sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported
    98. End With
    99. txtCpu.Text = sInfoString
    100.  
    101. End Sub
    102. 'Conversions from code to string were developed
    103. 'based on information in WMI SDK documentation
    104. Private Function AvailabilityToString(Code As Integer) As String
    105. Dim sAns As String
    106.  
    107. Select Case Code
    108.     Case 1, 2
    109.         sAns = "Unknown"
    110.     Case 3
    111.         sAns = "Running/Full Power"
    112.     Case 4
    113.         sAns = "Warning"
    114.     Case 5
    115.         sAns = "In Test"
    116.     Case 6
    117.         sAns = "Not Applicable"
    118.     Case 7
    119.         sAns = "Power Off"
    120.     Case 8
    121.         sAns = "Off Line"
    122.     Case 9
    123.         sAns = "Off Duty"
    124.     Case 10
    125.         sAns = "Degraded"
    126.     Case 11
    127.         sAns = "Not Installed"
    128.     Case 12
    129.         sAns = "Install Error"
    130.     Case 13
    131.         sAns = "Power Save - Unknown"
    132.     Case 14
    133.         sAns = "Power Save - Low Power Mode"
    134.     Case 15
    135.         sAns = "Power Save - Standby"
    136.     Case 16
    137.         sAns = "Power Cycle"
    138.     Case 17
    139.         sAns = "Power Save - Warning"
    140.     Case Else
    141.         sAns = "Unknown"
    142. End Select
    143. AvailabilityToString = sAns
    144.  
    145. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width