| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1256 人关注过本帖
标题:用diskid.dll和disk32.dll获得硬盘序列号
只看楼主 加入收藏
qzxm
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-11-3
收藏
 问题点数:0 回复次数:1 
用diskid.dll和disk32.dll获得硬盘序列号

今天夜里两点,还没有入睡,就把取得序列号的代码简单写了一下,没有分别在不同的系统上调试,只在win2000下调试通过,如果有问题的话,请告诉我,我再修改

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 DRIVER_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 VarPtr(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 硬盘 
2005-11-18 19:19
PJPX
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2009-7-27
收藏
得分:0 
回复 楼主 qzxm
运行后,出现错误提示(文件未找到:DiskID.DLL)
2010-02-05 14:13
快速回复:用diskid.dll和disk32.dll获得硬盘序列号
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026259 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved