'申明api函数,读程序所在硬盘序列号 Public 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)'读程序所在硬盘序列号函数 Public Function DriveSerial(ByVal sDrv As String) As Long Dim RetVal As Long Dim str As String * 256 Dim str2 As String * 256 Dim a As Long Dim b As Long Call GetVolumeInformation(sDrv & ":\", str, 256, RetVal, a, b, str2, 256) DriveSerial = RetVal End Function用法: '硬盘序列号 Text1 = DriveSerial("c")
Public 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)'读程序所在硬盘序列号函数
Public Function DriveSerial(ByVal sDrv As String) As Long
Dim RetVal As Long
Dim str As String * 256
Dim str2 As String * 256
Dim a As Long
Dim b As Long Call GetVolumeInformation(sDrv & ":\", str, 256, RetVal, a, b, str2, 256)
DriveSerial = RetVal
End Function用法:
'硬盘序列号
Text1 = DriveSerial("c")