Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpszVolumeNameBuffer As String, _
ByVal lVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpszFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Public Function GetVolumeSerialNumber(ByVal RootPath As String) As String
Dim lpszVolumeNameBuffer As String
Dim lpszFileSystemNameBuffer As String
Dim lVolumeNameSize As Long
Dim lpVolumeSerialNumber As Long
Dim lpMaximumComponentLength As Long
Dim lpFileSystemFlags As Long
Dim nFileSystemNameSize As Long
Dim lRetVal As Long
lpVolumeSerialNumber = 0
lpMaximumComponentLength = 0
lpFileSystemFlags = 0
lpszVolumeNameBuffer = Space$(255)
lpszFileSystemNameBuffer = Space(255)
lVolumeNameSize = Len(lpszVolumeNameBuffer)
nFileSystemNameSize = Len(lpszFileSystemNameBuffer)
lRetVal = GetVolumeInformation(RootPath, _
lpszVolumeNameBuffer, _
lVolumeNameSize, _
lpVolumeSerialNumber, _
lpMaximumComponentLength, _
lpFileSystemFlags, _
lpszFileSystemNameBuffer, _
nFileSystemNameSize)
GetVolumeSerialNumber = Hex$(lpVolumeSerialNumber)
End Function
Private Sub Command1_Click()
Dim sRetVal As String
sRetVal = GetVolumeSerialNumber("C:\")
MsgBox "VolumeSerialNumber is: " & sRetVal
End Sub
只需在窗体建一个COMMAND1。
温馨提示:答案为网友推荐,仅供参考