新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)
Private Sub Command1_Click()
MsgBox GetSerialNumber("C")
End Sub
Public Function GetSerialNumber(sDrive As String) As Long
Dim ser As Long
Dim s As String * MAX_FILENAME_LEN
Dim s2 As String * MAX_FILENAME_LEN
Dim i As Long
Dim j As Long
Call GetVolumeInformation(sDrive + ":\" & Chr$(0), s, MAX_FILENAME_LEN, ser, i, j, s2, MAX_FILENAME_LEN)
GetSerialNumber = ser
End Function