Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Public Function GetSN(DriveLetter As String) As String Dim SerialNum As Long Dim VolNameBuf As String Dim FileSysNameBuf As String Select Case Len(DriveLetter) Case 1 If LCase(DriveLetter) Like "[a-z]" Then DriveLetter = Left(DriveLetter, 1) & ":\" Else GetSN = "Error - Bad drive designation" End If Case 2 If LCase(DriveLetter) Like "[a-z]:" Then DriveLetter = DriveLetter & "\" Else GetSN = "Error - Bad drive designation" End If Case 3 If LCase(DriveLetter) Like "[!a-z]:\" Then GetSN = "Error - Bad drive designation" End If Case Else GetSN = "Error - Bad drive designation" End Select If Len(GetSN) = 0 Then VolNameBuf = String(255, Chr(0)) FileSysNameBuf = String(255, Chr$(0)) GetVolumeInformation DriveLetter, VolNameBuf, Len(VolNameBuf), SerialNum, 0, 0, FileSysNameBuf, Len(FileSysNameBuf) GetSN = Right("00000000" & Hex(SerialNum), 8) End If End Function
Ответить
|