• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

用diskid.dll和disk32.dll获得硬盘序列号

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 55次 | 进入软件测试论坛讨论

领测软件测试网

       今天夜里两点,还没有入睡,就把取得序列号的代码简单写了一下,没有分别在不同的系统上调试,只在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可从下载,diskid32.dll可从下载


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网