用diskid.dll和disk32.dll獲得硬碟序列號 (轉)

themoney發表於2007-10-01
用diskid.dll和disk32.dll獲得硬碟序列號 (轉)[@more@]

  今天夜裡兩點,還沒有入睡,就把取得序列號的程式碼簡單寫了一下,沒有分別在不同的上,只在下除錯透過,如果有問題的話,請告訴我,我再修改

1.diskid.dll實現:

Option Explicit
Private Declare Function IsWinNT Lib "DiskID.DLL" () As Long
Private Declare Function ReadPhysicalDrive9X Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Declare Function ReadPhysicalDriveInNT Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long

Private Type _INFO_OK
  ModalNumber(39) As Byte
  SerialNumber(19) As Byte
  ControlNum(7) As Byte
  DriveType As Long
  Cylinders As Long
  Heads As Long
  Sectors As Long
End Type

Private Sub Command1_Click()
  Dim x As DRIVER_INFO_OK
  Dim i As Long
  If IsWinNT = 1 Then
  i = ReadPhysicalDriveInNT(ByVal 0, ByVal Vtr(x), ByVal 256)
  Else
  i = ReadPhysicalDrive9X(ByVal 0, ByVal VarPtr(x), ByVal 256)
  End If
  Dim s As String
  s = StrConv(x.ModalNumber, vbUnicode)
  s = Left(s, InStr(1, s, Chr(0)) - 1)
  MsgBox "廠商程式碼為:" + s
  s = StrConv(x.SerialNumber, vbUnicode)
  s = Left(s, InStr(1, s, Chr(0)) - 1)
  MsgBox "序列號為:" + s
End Sub

2.呼叫diskid32.dll實現:

Option Explicit
Private Declare Function DiskID32 Lib "DiskID32.DLL" (ByRef DiskModel As Byte, ByRef DiskID As Byte) As Long

Private Sub Command1_Click()
  Dim DiskModel(31) As Byte, DiskID(31) As Byte, i As Integer, Model As String, ID As String
  If DiskID32(DiskModel(0), DiskID(0)) <> 1 Then
  MsgBox "get diskid32 err"
  Exit Sub
  End If
  For i = 0 To 31
  If Chr(DiskModel(i)) <> Chr(0) Then
  Model = Model & Chr(DiskModel(i))
  End If
  If Chr(DiskID(i)) <> Chr(0) Then
  ID = ID & Chr(DiskID(i))
  End If
  Next
  MsgBox "硬體產生程式碼為:" + Model
  MsgBox "硬碟序列號為:" + ID

End Sub

說明:diskid.dll可從,diskid32.dll可從?id=1149&no=1">下載


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10794571/viewspace-974320/,如需轉載,請註明出處,否則將追究法律責任。

相關文章