聲明:
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
代碼:
Function GetSerialNumber(sRoot As String) As Long
Dim lSerialNum As Long
Dim R As Long
Dim sTemp1 As String, sTemp2 As String
strLabel = String$(255, Chr$(0))
注釋: 磁盤卷標(biāo)
strType = String$(255, Chr$(0))
注釋: 文件系統(tǒng)類型 一般為 FAT
R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType))
GetSerialNumber = lSerialNum
注釋:在 strLabel 中為 磁盤卷標(biāo)
注釋:在 strType 中為 文件系統(tǒng)類型
End Function
用法:
當(dāng)驅(qū)動器不存在時,函數(shù)返回 0。如果是個非根目錄,也將返回 0:
lSerial = GetSerialNumber("c:\")