在VB中获得硬盘分区的序列号
在计算软件注册码时经常用到的是硬盘序列号,下面我们通过VB来获得C盘的序列号,其他分区的一样。
首先:新建一个标准EXE工程,双击窗体,输入以下代码:
复制内容到剪贴板
代码:
Private Declare Function GetVolumeInformation 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 Form_Load()
On Error GoTo Err_Form_Load
Dim AA, VIF, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
AA = GetVolumeInformation("C:", VolName, 256, VIF, Maxlen, Sysflag, FsysName, 256)
MsgBox Hex(VIF)
Err_Form_Load:
End Sub