VB取磁盤(pán)序列號(hào)卷標(biāo)和文件系統(tǒng)類(lèi)型

字號(hào):

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