|
-
Aug 21st, 2001, 08:42 AM
#1
Thread Starter
Frenzied Member
get the hard disk label
Hi VBers
How do you get the hard disk label through vb?
Thanx in advance,
Clint
-
Aug 21st, 2001, 08:59 AM
#2
Thread Starter
Frenzied Member
-
Aug 21st, 2001, 09:00 AM
#3
Member
It's only been 15 mins, I've been searching MSDN and the board.
-
Aug 21st, 2001, 09:00 AM
#4
Fanatic Member
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.
-
Aug 21st, 2001, 09:02 AM
#5
Member
-
Aug 21st, 2001, 09:08 AM
#6
Thread Starter
Frenzied Member
Thanx guys i appreciate it
-
Aug 21st, 2001, 09:09 AM
#7
-
Aug 21st, 2001, 09:09 AM
#8
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
Last edited by Hack; Jun 5th, 2002 at 05:47 PM.
-
Aug 21st, 2001, 09:14 AM
#9
Thread Starter
Frenzied Member
Ok...I got another question.
Is the Serial Number of a hard drive always the same length?
-
Aug 21st, 2001, 09:16 AM
#10
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|