转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
纯VB代码取得硬盘的物理序列号         ★★★★

纯VB代码取得硬盘的物理序列号

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3054 更新时间:2009/4/23 15:37:17

    网上有很多获取硬盘序列号的代码,但大部分都只能取得逻辑分区的序列号,而不能取得硬盘的物理序列号。我们知道,逻辑分区的序列号是FORMAT时产生的,重新FORMAT将会改变。这对于要求唯一识别码的程式来说是致命的。这段代码利用API可以取得物理硬盘的很多特性,包括硬盘出厂时的唯一编号。这段代码我是从CSDN论坛获得,原作者不详。我将其稍做修改和增添,独立出两个常用的函数:GetDiskVolume 、GetHardDiskInfo  ......

''''============================================
''''模块功能:取得硬盘的信息
''''编    程:来自互联网,阿勇修改
''''更新日期:2005/7/8
''''调用方法:
''''   GetDiskVolume() 取得逻辑盘的序列号
''''   GetHardDiskInfo() 取得物理盘的型号或序列号
''''============================================

Private Const MAX_IDE_DRIVES As Long = 4   '''' Max number of drives assuming primary/secondary, master/slave topology
Private Const READ_ATTRIBUTE_BUFFER_SIZE As Long = 512
Private Const IDENTIFY_BUFFER_SIZE As Long = 512
Private Const READ_THRESHOLD_BUFFER_SIZE As Long = 512
Private Const DFP_GET_VERSION As Long = &H74080
Private Const DFP_SEND_DRIVE_COMMAND As Long = &H7C084
Private Const DFP_RECEIVE_DRIVE_DATA As Long = &H7C088

Private Type GETVERSIONOUTPARAMS
    bVersion As Byte       '''' Binary driver version.
    bRevision As Byte      '''' Binary driver revision.
    bReserved As Byte      '''' Not used.
    bIDEDeviceMap As Byte  '''' Bit map of IDE devices.
    fCapabilities As Long  '''' Bit mask of driver capabilities.
    dwReserved(3) As Long  '''' For future use.
End Type

Private Const CAP_IDE_ID_FUNCTION As Long = 1               '''' ATA ID command supported
Private Const CAP_IDE_ATAPI_ID As Long = 2                  '''' ATAPI ID command supported
Private Const CAP_IDE_EXECUTE_SMART_FUNCTION As Long = 4    '''' SMART commannds supported

Private Type IDEREGS
    bFeaturesReg As Byte       '''' Used for specifying SMART "commands".
    bSectorCountReg As Byte    '''' IDE sector count register
    bSectorNumberReg As Byte   '''' IDE sector number register
    bCylLowReg As Byte         '''' IDE low order cylinder value
    bCylHighReg As Byte        '''' IDE high order cylinder value
    bDriveHeadReg As Byte      '''' IDE drive/head register
    bCommandReg As Byte        '''' Actual IDE command.
    bReserved As Byte          '''' reserved for future use.  Must be zero.
End Type

Private Type SENDCMDINPARAMS
    cBufferSize As Long        '''' Buffer size in bytes
    irDriveRegs As IDEREGS     '''' Structure with drive register values.
    bDriveNumber As Byte       '''' Physical drive number to send
    '''' command to (0,1,2,3).
    bReserved(2) As Byte       '''' Reserved for future expansion.
    dwReserved(3) As Long      '''' For future use.
    bBuffer(0) As Byte         '''' Input buffer.
End Type

Private Const IDE_ATAPI_ID As Long = &HA1  '''' Returns ID sector for ATAPI.
Private Const IDE_ID_FUNCTION As Long = &HEC  '''' Returns ID sector for ATA.
Private Const IDE_EXECUTE_SMART_FUNCTION As Long = &HB0  '''' Performs SMART cmd.
Private Const SMART_CYL_LOW As Long = &H4F
Private Const SMART_CYL_HI As Long = &HC2

Private Type DRIVERSTATUS
    bDriverError As Byte       '''' Error code from driver,
    bIDEStatus As Byte         '''' Contents of IDE Error register.
    bReserved(1) As Byte       '''' Reserved for future expansion.
    dwReserved(1) As Long      '''' Reserved for future expansion.
End Type

Private Const SMART_NO_ERROR As Long = 0  '''' No error
Private Const SMART_IDE_ERROR As Long = 1  '''' Error from IDE controller
Private Const SMART_INVALID_FLAG As Long = 2  '''' Invalid command flag
Private Const SMART_INVALID_COMMAND As Long = 3  '''' Invalid command byte
Private Const SMART_INVALID_BUFFER As Long = 4  '''' Bad buffer (null, invalid addr..)
Private Const SMART_INVALID_DRIVE As Long = 5  '''' Drive number not valid
Private Const SMART_INVALID_IOCTL As Long = 6   '''' Invalid IOCTL
Private Const SMART_ERROR_NO_MEM As Long = 7  '''' Could not lock user''''s buffer
Private Const SMART_INVALID_REGISTER As Long = 8  '''' Some IDE Register not valid
Private Const SMART_NOT_SUPPORTED As Long = 9  '''' Invalid cmd flag set
Private Const SMART_NO_IDE_DEVICE As Long = 10 '''' Cmd issued to device not present

Private Type SENDCMDOUTPARAMS
    cBufferSize As Long        '''' Size of bBuffer in bytes
    drvStatus As DRIVERSTATUS  '''' Driver status structure.
    bBuffer(0) As Byte         '''' Buffer of arbitrary length in which to store the data read from the                                          '''' drive.
End Type

Private Const SMART_READ_ATTRIBUTE_VALUES As Long = &HD0    '''' ATA4: Renamed
Private Const SMART_READ_ATTRIBUTE_THRESHOLDS As Long = &HD1    '''' Obsoleted in ATA4!
Private Const SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE As Long = &HD2
Private Const SMART_SAVE_ATTRIBUTE_VALUES As Long = &HD3
Private Const SMART_EXECUTE_OFFLINE_IMMEDIATE As Long = &HD4    '''' ATA4
Private Const SMART_ENABLE_SMART_OPERATIONS As Long = &HD8
Private Const SMART_DISABLE_SMART_OPERATIONS As Long = &HD9
Private Const SMART_RETURN_SMART_STATUS As Long = &HDA

Private Type DRIVEATTRIBUTE
    bAttrID As Byte        '''' Identifies which attribute
    wStatusFlags As Integer    '''' see bit definitions below
    bAttrValue As Byte     '''' Current normalized value
    bWorstValue As Byte    '''' How bad has it ever been?
    bRawValue(5) As Byte   '''' Un-normalized value
    bReserved As Byte      '''' ...
End Type

Private Type ATTRTHRESHOLD
    bAttrID As Byte            '''' Identifies which attribute
    bWarrantyThreshold As Byte '''' Triggering value
    bReserved(9) As Byte      '''' ...
End Type

Private Type IDSECTOR
    wGenConfig As Integer
    wNumCyls As Integer
    wReserved As Integer
    wNumHeads As Integer
    wBytesPerTrack As Integer
    wBytesPerSector As Integer
    wSectorsPerTrack As Integer
    wVendorUnique(2) As Integer
    sSerialNumber(19) As Byte
    wBufferType As Integer
    wBufferSize As Integer
    wECCSize As Integer
    sFirmwareRev(7) As Byte
    sModelNumber(39) As Byte
    wMoreVendorUnique As Integer
    wDoubleWordIO As Integer
    wCapabilities As Integer
    wReserved1 As Integer
    wPIOTiming As Integer
    wDMATiming As Integer
    wBS As Integer
    wNumCurrentCyls As Integer
    wNumCurrentHeads As Integer
    wNumCurrentSectorsPerTrack As Integer
    ulCurrentSectorCapacity(3) As Byte    ''''这里只能用byte,因为VB没有无符号的LONG型变量
    wMultSectorStuff As Integer
    ulTotalAddressableSectors(3) As Byte   ''''这里只能用byte,因为VB没有无符号的LONG型变量
    wSingleWordDMA As Integer
    wMultiWordDMA As Integer
    bReserved(127) As Byte
End Type

Private Const ATTR_INVALID As Long = 0
Private Const ATTR_READ_ERROR_RATE As Long = 1
Private Const ATTR_THROUGHPUT_PERF As Long = 2
Private Const ATTR_SPIN_UP_TIME As Long = 3
Private Const ATTR_START_STOP_COUNT As Long = 4
Private Const ATTR_REALLOC_SECTOR_COUNT As Long = 5
Private Const ATTR_READ_CHANNEL_MARGIN As Long = 6
Private Const ATTR_SEEK_ERROR_RATE As Long = 7
Private Const ATTR_SEEK_TIME_PERF As Long = 8
Private Const ATTR_POWER_ON_HRS_COUNT As

[1] [2] [3]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台