Option Explicit
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
Public Function VolumeName(Optional Drive As String = "C:\")
Dim sBuffer As String
sBuffer = Space$(255)
'fix bad parameter values
If Len(Drive) = 1 Then Drive = Drive & ":\"
If Len(Drive) = 2 And Right$(Drive, 1) = ":" _
Then Drive = Drive & "\"
If GetVolumeInformation(Drive, sBuffer, Len(sBuffer), 0, 0, 0, _
Space$(255), 255) = 0 Then
Err.Raise Err.LastDllError, , _
"A system call returned an error code of " _
& Err.LastDllError
Else
VolumeName = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
End Function
Get the name of a Drive
code:
0 comments:
Post a Comment