当前位置:首页 » 程序代码 » 正文

VB编程:判断磁盘序列号

在VB编程中,有时需要判断电脑硬盘序列号,并以此生成所谓这台电脑的机器码,如果软件需要注册,就以此机器码来算出对应的注册码。

先在窗体模块输入VB代码:
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
 
再做一个判断磁盘号的函数
Function GetSerialNumber(sRoot As String) As Long
Dim lSerialNum As Long, strtype As String, strlabel As String
  strtype = String$(255, Chr$(0))
  GetVolumeInformation sRoot, strlabel, Len(strlabel), lSerialNum, 0, 0, strtype, Len(strtype)
  MsgBox "磁盘序列号:" & Hex$(lSerialNum)
  MsgBox "文件系统:" & strtype
End Function

在窗体画一个按钮1,点击代码如下:
Private Sub Command1_Click()
GetSerialNumber "c:\"
End Sub

运行此程序,会弹出相应的提示,告诉C盘的磁盘序列号,这个VB源代码,你可再改进一下,生成D盘等磁盘的序列号。

来源:济亨网

本文链接:http://wb98.com/post/25.html

VB代码  API  
    << 上一篇 下一篇 >>

    湘公网安备 43011102000514号 - 湘ICP备08100508号