Results 1 to 3 of 3

Thread: GetVolumeInformationA - Hard Drive Serial Number

  1. #1
    needaname16
    Guest

    Talking GetVolumeInformationA - Hard Drive Serial Number

    Hi Everyone,

    Can someone tell me if the GetVolumeInformationA function of the kernel32.dll is the physical[/B] hard driive serial number or the serial number of the volume that can be changed on a reformat.

    If it is the volume serial number can someone tell me how to get the physical serial number of the hard drive.

    Thanx a mill

    Needaname16

  2. #2
    jim mcnamara
    Guest
    You're confusing volume label with serial number. It's what you want.

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

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