How to get HDD Serial?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aftab Ahmad
    New Member
    • Jan 2015
    • 49

    How to get HDD Serial?

    Hi!

    How I can get my Hard Disk Serial using vba like in picture. I have Access 2019 64 Bit. Also, either this will be change after installing new windows or not?
    Attached Files
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    Try this:

    Code:
    Option Compare Database
    Option Explicit
    
    Private Declare Function _
        apiGetVolumeInformation _
            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
    
    Private Const MAX_PATH = 260
    
    Function DriveSerial( _
        strDrive As String) _
        As String
    ' Usage: DriveSerial("C:\")
    ' returns the Serial Number
    'of the Drive assigned to C:\
        Dim lngReturn   As Long
        Dim lngTemp1    As Long
        Dim lngTemp2    As Long
        Dim lngSerial   As Long
        Dim strTemp1    As String
        Dim strTemp2    As String
        Dim strSerial   As String
    
        strTemp1 = Space(MAX_PATH)
        strTemp2 = Space(MAX_PATH)
        lngReturn = _
            apiGetVolumeInformation( _
                lpRootPathName:=strDrive, _
                lpVolumeNameBuffer:=strTemp1, _
                nVolumeNameSize:=Len(strTemp1), _
                lpVolumeSerialNumber:=lngSerial, _
                lpMaximumComponentLength:=lngTemp1, _
                lpFileSystemFlags:=lngTemp2, _
                lpFileSystemNameBuffer:=strTemp2, _
                nFileSystemNameSize:=Len(strTemp2))
        strSerial = Trim(Hex(lngSerial))
        strSerial = String(8 - Len(strSerial), "0") & strSerial
        strSerial = Left(strSerial, 4) & "-" & Right(strSerial, 4)
        DriveSerial = strSerial
    End Function
    Hope that hepps!

    Comment

    Working...