Results 1 to 10 of 10

Thread: get the hard disk label

  1. #1

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545

    get the hard disk label

    Hi VBers

    How do you get the hard disk label through vb?

    Thanx in advance,
    Clint

  2. #2

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    I must find some interesting questions to ask since nobody seems to know the answer to any of them

  3. #3
    It's only been 15 mins, I've been searching MSDN and the board.

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Look up information on the GetVolumeInformation API. I think it will allow you to get what you need. Take a look here and see if it helps.

  5. #5

  6. #6

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Thanx guys i appreciate it

  7. #7
    No prob. And thanks to jbart, too.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I thought someone would have answered this by now, so I didn't bother. Try this:
    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.  
    36. Private Function HiWord(dw As Long) As Integer
    37.  
    38.     HiWord = (dw And &HFFFF0000) \ &H10000
    39.  
    40. End Function
    41.  
    42.  
    43. Private Function LoWord(dw As Long) As Integer
    44.  
    45.     If dw And &H8000& Then
    46.         LoWord = dw Or &HFFFF0000
    47.     Else
    48.         LoWord = dw And &HFFFF&
    49.     End If
    50.    
    51. End Function
    52.  
    53. 'To Display The Volume Name And Serial Number:
    54. Dim PathName As String
    55.    Dim DrvVolumeName As String
    56.    Dim DrvSerialNo As String
    57.    PathName$ = "c:\"
    58.    GetVolume PathName, DrvVolumeName, DrvSerialNo
    59.    MsgBox "Drive Statistics for " & UCase$(PathName) & ": " & "Volume Label " & DrvVolumeName & ", " & "Volume Serial No " & DrvSerialNo
    Last edited by Hack; Jun 5th, 2002 at 05:47 PM.

  9. #9

    Thread Starter
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Ok...I got another question.

    Is the Serial Number of a hard drive always the same length?

  10. #10
    Yes, but it can change each time the hard drive is formatted. There are even some tools to change it.

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