Results 1 to 5 of 5

Thread: Retrieving Serial Numbers

  1. #1

    Thread Starter
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Retrieving Serial Numbers

    Hi! I am assigned by my boss to retrieve the serial numbers of the following: Hard Disk, CPU, Video Card, Memory(RAM), Motherboard and monitor. Is it possible to do it in vb? please help...
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

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

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Hard Drive Serial Number

    VB Code:
    1. Public Declare Function GetVolumeSerialNumber Lib "kernel32.dll" 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. Public Function VolumeSerialNumber(ByVal RootPath As String) As String
    3.     Dim VolLabel As String
    4.     Dim VolSize As Long
    5.     Dim Serial As Long
    6.     Dim MaxLen As Long
    7.     Dim Flags As Long
    8.     Dim Name As String
    9.     Dim NameSize As Long
    10.     Dim s As String
    11.  
    12.     If GetVolumeSerialNumber(RootPath, VolLabel, VolSize, Serial, MaxLen, Flags, Name, NameSize) Then
    13.         'Create an 8 character string
    14.         s = Format(Hex(Serial), "00000000")
    15.         'Adds the '-' between the first 4 characters and the last 4 characters
    16.         VolumeSerialNumber = Left(s, 4) + "-" + Right(s, 4)
    17.     Else
    18.         'If the call to API function fails the function returns a zero serial number
    19.         VolumeSerialNumber = "0000-0000"
    20.     End If
    21. End Function
    22.  
    23. ' Usage :
    24.  
    25. GotNum = VolumeSerialNumber("C:\")
    26.  
    27.  
    28. ' OR ##########################
    29.  
    30. Public Function SerialNumber() As Long
    31.  
    32. Dim fso As Object
    33.  
    34. Set fso = CreateObject("Scripting.FileSystemObject")
    35.  
    36. Dim Drive As Object
    37.  
    38. Set Drive = fso.GetDrive(fso.GetDriveName
    39. (fso.GetAbsolutePathName(App.Path)))
    40.  
    41. SerialNumber = Abs(Drive.SerialNumber)
    42.  
    43. Set fso = Nothing
    44.  
    45. Set Drive = Nothing
    46.  
    47. End Function

    If Hard Drive is Formatted, a different Serail Number will be generated (I think).
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    More from Hack :

    VB Code:
    1. Private Type MEMORYSTATUS
    2.     dwLength As Long
    3.     dwMemoryLoad As Long
    4.     dwTotalPhys As Long
    5.     dwAvailPhys As Long
    6.     dwTotalPageFile As Long
    7.     dwAvailPageFile As Long
    8.     dwTotalVirtual As Long
    9.     dwAvailVirtual As Long
    10. End Type
    11.  
    12. Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
    13.  
    14. Dim MS As MEMORYSTATUS
    15. MS.dwLength = Len(MS)
    16. GlobalMemoryStatus MS
    17. MsgBox MS.dwMemoryLoad & " percentage memory used"
    18. MsgBox MS.dwTotalPhys & " total amount of physical memory in bytes"
    19. MsgBox MS.dwAvailPhys & " available physical memory"
    20. MsgBox MS.dwTotalPageFile & " total amount of memory in the page file"
    21. MsgBox MS.dwAvailPageFile & " available amount of memory in the page file"
    22. MsgBox MS.dwTotalVirtual & " total amount of virtual memory"
    23. MsgBox MS.dwAvailVirtual & " available virtual memory"
    24.  
    25. Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
    26. Private Type SYSTEM_INFO
    27.         dwOemID As Long
    28.         dwPageSize As Long
    29.         lpMinimumApplicationAddress As Long
    30.         lpMaximumApplicationAddress As Long
    31.         dwActiveProcessorMask As Long
    32.         dwNumberOrfProcessors As Long
    33.         dwProcessorType As Long
    34.         dwAllocationGranularity As Long
    35.         dwReserved As Long
    36. End Type
    37.  
    38. Dim InfoResult As SYSTEM_INFO
    39. GetSystemInfo InfoResult
    40. MsgBox "Your CPU type is " & InfoResult.dwProcessorType
    41. MsgBox "You have " & InfoResult.dwNumberOrfProcessors & " processor(s)"
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5
    Hyperactive Member VB IT's Avatar
    Join Date
    Feb 2003
    Posts
    381

    Post What IF?

    How I Can Get Processor Serial Number In Windows 98? (WMI Not install in Win98)

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