说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB如何取得磁盘序列号?

HTML文档下载 WORD文档下载 PDF文档下载
VB如何取得磁盘序列号?


调用API函数 GetVolumeInformation。

API声明:

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()
  Dim sDriveLetter As String
  Dim RetVal As Long
  Dim lpName As String
  Dim nSize As Long
  Dim nSerial As Long
  Dim lpMaxComp As Long
  Dim nFileFlags As Long
  Dim lpFileName As String
  lpName = Space(255)
  lpFileName = Space(255)
  nSize = 255

  sDriveLetter = "a:\" ’这里你可以指定任何盘号

  RetVal = GetVolumeInformation(sDriveLetter, lpName, _
   nSize, nSerial, lpMaxComp, nFileFlags, lpFileName, nSize)
  '你可以看出,不仅能得到序列号,还可以得到其他很多信息

  If RetVal = 0 Then
    '这里是你的错误处理代码
    Exit Sub 'Quit the subroutine
  Else
    lblDriveSerial.Caption = CStr(nSerial)
    '假定你已经建立了这个标签,将在标签上显示序列号.
  End If
End Sub

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘