新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function GetVolumeInformation2 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 Command1_Click()
Dim drvserialno As Long
Dim mydrvlabel As String * 256
Dim myfilesys As String * 256
Dim i As Long
Dim j As Long
Dim x As Long
x = GetVolumeInformation2("C:\", mydrvlabel, 256, drvserialno, i, j, myfilesys, 256)
Debug.Print "Label of C Drive is " & mydrvlabel
Debug.Print "It's serial number = " & Hex(serialno)
Debug.Print "FileSystem = " & myfilesys
End Sub
运行结果:
Label of C Drive is my-c
It's serial number = 0
FileSystem = NTFS