Results 1 to 11 of 11

Thread: How to get hardware Info. using VB6?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Location
    Iran
    Posts
    5

    Question How to get hardware Info. using VB6?

    As a programmer, I need my program to get system information about some hardware IDs like CPU ID and manufavteuring date, as well HDD serial number. (this way the system can be uniquely identified by me.) Any solution?
    I need a direct access to these system info., because registry keys are in different location in WINXP or WIN98, etc, and can not be used in all the cases.

    Thank you in advance and waiting...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    HDD serial number is retrieved by using an API.
    VB Code:
    1. 'Example by Alexey ([email protected])
    2. Private Const DRIVE_UNKNOWN = 0
    3. Private Const DRIVE_ABSENT = 1
    4. Private Const DRIVE_REMOVABLE = 2
    5. Private Const DRIVE_FIXED = 3
    6. Private Const DRIVE_REMOTE = 4
    7. Private Const DRIVE_CDROM = 5
    8. Private Const DRIVE_RAMDISK = 6
    9. ' returns errors for UNC Path
    10. Private Const ERROR_BAD_DEVICE = 1200&
    11. Private Const ERROR_CONNECTION_UNAVAIL = 1201&
    12. Private Const ERROR_EXTENDED_ERROR = 1208&
    13. Private Const ERROR_MORE_DATA = 234
    14. Private Const ERROR_NOT_SUPPORTED = 50&
    15. Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
    16. Private Const ERROR_NO_NETWORK = 1222&
    17. Private Const ERROR_NOT_CONNECTED = 2250&
    18. Private Const NO_ERROR = 0
    19.  
    20.  
    21. Private Declare Function WNetGetConnection Lib "mpr.dll" Alias _
    22.         "WNetGetConnectionA" (ByVal lpszLocalName As String, _
    23.         ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
    24. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
    25.     "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
    26.     ByVal lpBuffer As String) As Long
    27. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    28.     (ByVal nDrive As String) As Long
    29. Private Function fGetDrives() As String
    30. 'Returns all mapped drives
    31.     Dim lngRet As Long
    32.     Dim strDrives As String * 255
    33.     Dim lngTmp As Long
    34.     lngTmp = Len(strDrives)
    35.     lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
    36.     fGetDrives = Left(strDrives, lngRet)
    37. End Function
    38. Private Function fGetUNCPath(strDriveLetter As String) As String
    39.     On Local Error GoTo fGetUNCPath_Err
    40.  
    41.  
    42.     Dim Msg As String, lngReturn As Long
    43.     Dim lpszLocalName As String
    44.     Dim lpszRemoteName As String
    45.     Dim cbRemoteName As Long
    46.     lpszLocalName = strDriveLetter
    47.     lpszRemoteName = String$(255, Chr$(32))
    48.     cbRemoteName = Len(lpszRemoteName)
    49.     lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName, _
    50.                                        cbRemoteName)
    51.     Select Case lngReturn
    52.         Case ERROR_BAD_DEVICE
    53.             Msg = "Error: Bad Device"
    54.         Case ERROR_CONNECTION_UNAVAIL
    55.             Msg = "Error: Connection Un-Available"
    56.         Case ERROR_EXTENDED_ERROR
    57.             Msg = "Error: Extended Error"
    58.         Case ERROR_MORE_DATA
    59.                Msg = "Error: More Data"
    60.         Case ERROR_NOT_SUPPORTED
    61.                Msg = "Error: Feature not Supported"
    62.         Case ERROR_NO_NET_OR_BAD_PATH
    63.                Msg = "Error: No Network Available or Bad Path"
    64.  
    65.  
    66.         Case ERROR_NO_NETWORK
    67.  
    68.                Msg = "Error: No Network Available"
    69.         Case ERROR_NOT_CONNECTED
    70.                Msg = "Error: Not Connected"
    71.         Case NO_ERROR
    72.                ' all is successful...
    73.     End Select
    74.     If Len(Msg) Then
    75.         MsgBox Msg, vbInformation
    76.     Else
    77.         fGetUNCPath = Left$(lpszRemoteName, cbRemoteName)
    78.     End If
    79. fGetUNCPath_End:
    80.     Exit Function
    81. fGetUNCPath_Err:
    82.     MsgBox Err.Description, vbInformation
    83.     Resume fGetUNCPath_End
    84. End Function
    85.  
    86.  
    87. Private Function fDriveType(strDriveName As String) As String
    88.     Dim lngRet As Long
    89.     Dim strDrive As String
    90.     lngRet = GetDriveType(strDriveName)
    91.     Select Case lngRet
    92.         Case DRIVE_UNKNOWN 'The drive type cannot be determined.
    93.             strDrive = "Unknown Drive Type"
    94.         Case DRIVE_ABSENT 'The root directory does not exist.
    95.             strDrive = "Drive does not exist"
    96.         Case DRIVE_REMOVABLE 'The drive can be removed from the drive.
    97.             strDrive = "Removable Media"
    98.         Case DRIVE_FIXED 'The disk cannot be removed from the drive.
    99.             strDrive = "Fixed Drive"
    100.         Case DRIVE_REMOTE  'The drive is a remote (network) drive.
    101.             strDrive = "Network Drive"
    102.         Case DRIVE_CDROM 'The drive is a CD-ROM drive.
    103.             strDrive = "CD Rom"
    104.         Case DRIVE_RAMDISK 'The drive is a RAM disk.
    105.             strDrive = "Ram Disk"
    106.     End Select
    107.     fDriveType = strDrive
    108. End Function
    109.  
    110.  
    111. Sub sListAllDrives()
    112.     Dim strAllDrives As String
    113.     Dim strTmp As String
    114.    
    115.     strAllDrives = fGetDrives
    116.     If strAllDrives <> "" Then
    117.         Do
    118.             strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) - 1)
    119.             strAllDrives = Mid$(strAllDrives, InStr(strAllDrives, vbNullChar) + 1)
    120.             Select Case fDriveType(strTmp)
    121.                 Case "Removable Media":
    122.                     Debug.Print "Removable drive :  " & strTmp
    123.                 Case "CD Rom":
    124.                     Debug.Print "   CD Rom drive :  " & strTmp
    125.                 Case "Fixed Drive":
    126.                     Debug.Print "    Local drive :  " & strTmp
    127.                 Case "Network Drive":
    128.                     Debug.Print "  Network drive :  " & strTmp
    129.                     Debug.Print "       UNC Path :  " & _
    130.                                 fGetUNCPath(Left$(strTmp, Len(strTmp) - 1))
    131.             End Select
    132.         Loop While strAllDrives <> ""
    133.     End If
    134. End Sub
    135.  
    136.  
    137. Private Sub Form_Load()
    138.     Debug.Print "All available drives: "
    139.     sListAllDrives
    140. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Processor Info...
    VB Code:
    1. Option Explicit
    2. 'Add reference to Microsoft WMI Scripting Object Library
    3. 'Add one command button (Command1)
    4. 'Add one textbox (txtProcessor)
    5. 'txtProcessor.MultiLine = True
    6. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    7.  
    8. Private Sub Command1_Click()
    9.    
    10.     'Processor Information
    11.     Dim oProcessors As Variant
    12.     Dim oProcessor As Variant
    13.  
    14.     Set oProcessors = GetObject("winmgmts:\\" & CompName).InstancesOf("Win32_Processor")
    15.     For Each oProcessor In oProcessors
    16.         txtProcessor.Text = txtProcessor.Text & oProcessor.Caption & vbNewLine
    17.         txtProcessor.Text = txtProcessor.Text & "Speed: " & oProcessor.currentclockspeed & " Mhz" & vbNewLine
    18.     Next
    19.  
    20. End Sub
    21.  
    22. Private Function CompName() As String
    23.    
    24.     Dim strString As String
    25.    
    26.     strString = String(255, Chr$(0))
    27.     GetComputerName strString, 255
    28.     strString = Left$(strString, InStr(1, strString, Chr$(0)))
    29.     strString = Left(strString, (Len(strString) - 1))
    30.     CompName = strString
    31.    
    32. End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Location
    Iran
    Posts
    5

    HDD Serial Number. What about it?

    Thanks a lot RobDog888, for the codes. It was very useful.

    HDD dirve list returns all logical paratitions, but not a 'hard' property of the HDD. Serial Numebr, electronically printed in a chipset inside HDD is what I am looking for.

    Will be very thankful if get such an API code.(As you mentioned it can be achieved using API).


    And finally, how can I access to a full reference of those magic codes that can do almost anythng using API? (Or to learn more about API itself, not to get fishes, but to learn fishing! )

    Best wishes

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Check out allapi.net for all the cool api tips, tricks, and definitions.
    VB Code:
    1. Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" _
    2. (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
    3. lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
    4. ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
    5. Private Sub Form_Load()
    6.     'KPD-Team 1998
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Dim Serial As Long, VName As String, FSName As String
    10.     'Create buffers
    11.     VName = String$(255, Chr$(0))
    12.     FSName = String$(255, Chr$(0))
    13.     'Get the volume information
    14.     GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
    15.     'Strip the extra chr$(0)'s
    16.     VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
    17.     FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
    18.     MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
    19. End Sub
    Closer?

    Let me know if you catch a fish!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Location
    Iran
    Posts
    5

    WINXP:Yes. WIN 98: No!

    Dear RobDog888

    Do not really want to ask about any problem occurs, but:

    You didn't mention any limitation with the CPU_Iinfo code you provided, but it doest not work on systems running win98 os. (Two tests and both failed) Error: "Run-time error '432', file name or class name not found during Automation Operation." Runing inside VB envirunment(Win98), while WMI is checked, returns an error in line: Set oProcessors = GetObject("winmgmts....
    In WIN XP everything goes fine anyway.
    Is it a os dependant code??


    HDD serial number (HDD_SN), on the other hand, returns different serial values for the same hardware (dual boot) running win98 and winxp. The phylosophy of using HDD_SN was to have a stable property for the hardware system. Is HDD_SN also OS dependant, or the program itself has a kind of inability?


    I didn't catch a fish, but trapped a bug!

    Waiting...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    For the HD serial number, it will return the serial number of the
    hard drive that is assigned to it whenever the drive gets
    formatted. So if you have a dual boot system, you will have one
    sn for 98 and one sn for xp.

    I know what serial number you are talking about because I am
    running dual raid mirrors and the raid controller utility software
    has a form that you can view the actual manufacturers hd serial
    number. Its proprietary to the hd manufacturer. I wish I knew too
    how to get THAT serial number.

    For the WMI requirements, I'm not sure if the parameter for the
    line - ).InstancesOf("Win32_Processor") needs to be different for
    98. May be something like "Win_16_Processor" since 98 is not
    really a 32 bit os, only simulated 32 bit.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Location
    Iran
    Posts
    5

    WMI Solution

    About WMI, I worked around it and found the solution last night. There is a WMI (Windows Managmant Instrumantation) Install program which is called WmiCore.exe and can be download from microsoft.com. I did so and installed the package under win98, and everything works fine!
    For WinXP and 2000, the package is installed at time of windows installation. However, win95, win98, win98se (also 2000?) require this package to make them enable Windows Managment ability.

    For the -let's say 'Printed-, HD serial number, or other 'hard' properties, if you found a clue, just let me know. This is usefu when you want to bind your programs just to user's PC hardware, so illegal copying would be almost impossible.

    Thank you very much once again, for all your help and support.

    Will be glad to hear from you at [email protected]


  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I am running Win2k sp4 and I have the WMI functionality.
    I think the ability to get the hd serial number would be
    dependant upon the hd manufacturer. I remember when I had a
    bad power chip on an old Western Digital hd, they had there own
    dos based utility to diagnose the drive and return any error
    codes along with the serial number, etc. I had another diagnostic
    utility for Maxtor drives which did the same thing and either one
    would not work on the other. Maybe there are some dos
    commands or ??? that are universal in returning the serial
    number. Possibly some assmebly code that will do it. I just
    remembered that I have a Utilities Assembly book that may have
    some examples. When I get home I will put it in my car to make
    sure I bring it to work tomorrow.


    :mike:
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Location
    Iran
    Posts
    5
    I found a similar topic here.[URL=http://www.vbforums.com/showthread.php?s=&threadid=234404]

    There u'll find a code that returns hd serial (not Volume Serial). The problem is that the code is for vb.net. Is there a way to change it to be run under vb6 ent.?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Looks like it has its limitations too. Only will work under XP.
    In case anyone wants to see the .Net code.

    VB Code:
    1. Dim mgmclass As New System.Management.ManagementClass("Win32_PhysicalMedia")
    2. Dim mgmcoll As Management.ManagementObjectCollection = mgmclass.GetInstances()
    3. Dim mgmenum As Management.ManagementObjectCollection.ManagementObjectEnumerator = mgmcoll.GetEnumerator
    4. mgmenum.MoveNext()
    5. MessageBox.Show(mgmenum.Current.Properties("SerialNumber").Value.ToString)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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