Hi VBers
How do you get the hard disk label through vb?
Thanx in advance,
Clint
Printable View
Hi VBers
How do you get the hard disk label through vb?
Thanx in advance,
Clint
I must find some interesting questions to ask since nobody seems to know the answer to any of them :D :D :D :D :D
It's only been 15 mins, I've been searching MSDN and the board.
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.
Agreed, I found some related info: http://www.vbforums.com/showthread.p...rd+drive+label
Thanx guys i appreciate it :)
No prob. :cool: And thanks to jbart, too. :)
I thought someone would have answered this by now, so I didn't bother. Try this:VB Code:
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 Private Sub GetVolume(PathName As String, DrvVolumeName As String, DrvSerialNo As String) Dim r As Long Dim pos As Integer Dim hword As Long Dim HiHexStr As String Dim lword As Long Dim LoHexStr As String Dim VolumeSN As Long Dim MaxFNLen As Long Dim UnusedStr As String Dim UnusedVal1 As Long Dim UnusedVal2 As Long 'pad the strings DrvVolumeName$ = Space$(14) UnusedStr$ = Space$(32) 'do what it says r = GetVolumeInformation(PathName, DrvVolumeName, Len(DrvVolumeName), VolumeSN&, UnusedVal1, UnusedVal2, UnusedStr, Len(UnusedStr$)) 'error check If r& = 0 Then Exit Sub 'determine the volume label pos = InStr(DrvVolumeName, Chr$(0)) If pos Then DrvVolumeName = Left$(DrvVolumeName, pos - 1) If Len(Trim$(DrvVolumeName)) = 0 Then DrvVolumeName = "(no label)" hword = HiWord(VolumeSN) lword = LoWord(VolumeSN) HiHexStr = Format$(Hex(hword), "0000") LoHexStr = Format$(Hex(lword), "0000") DrvSerialNo = HiHexStr & "-" & LoHexStr End Sub Private Function HiWord(dw As Long) As Integer HiWord = (dw And &HFFFF0000) \ &H10000 End Function Private Function LoWord(dw As Long) As Integer If dw And &H8000& Then LoWord = dw Or &HFFFF0000 Else LoWord = dw And &HFFFF& End If End Function 'To Display The Volume Name And Serial Number: Dim PathName As String Dim DrvVolumeName As String Dim DrvSerialNo As String PathName$ = "c:\" GetVolume PathName, DrvVolumeName, DrvSerialNo MsgBox "Drive Statistics for " & UCase$(PathName) & ": " & "Volume Label " & DrvVolumeName & ", " & "Volume Serial No " & DrvSerialNo
Ok...I got another question.
Is the Serial Number of a hard drive always the same length?
Yes, but it can change each time the hard drive is formatted. There are even some tools to change it.