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

直接从RING3获取硬盘序列号

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1526 更新时间:2009/4/23 18:59:29

''''****************************************************************
''''原作: Bardo
''''出处: 《东方热讯》网站
''''网址: www.easthot.net
''''****************************************************************
''''(如需转载,请不在删除以上信息,否则视为侵权!)
''''****************************************************************

    要这个有什么用?可以生成与硬件相关的注册码。控制软件不重复使用!那么,很多多人认为VB实现不了。自然没有找到方法,一定是实现不了。然而,感谢WWW,我们能在上面找到VC的源码,DELPHI的源码。但是VB的就是见不到。为此,我决定将VC的源码改成VB的,以下即是:

''''VC原作说明部分(再发行时,请注意采用注解的方式,请不要删除的方式侵权,谢谢!)
''''*************************************************************************
''''通常情况下,我们通过=&HEC命令对IDE端口进行监测.获取硬盘信息.
''''一般情况下,我们就写个VXD或者DRIVER来完成.但是现在,通过MS的S.M.A.R.T.接口,
''''我们可以直接从RING3调用API DeviceIoControl()来获取硬盘信息.下面乃是我的例程:
''''另外,也有编译好的版本供大家平时使用.欢迎下载.
''''/*+++
''''HDID.CPP
''''Written by Lu Lin
''''http://lu0.126.com
''''2000.11.3
''''---*/
''''*************************************************************************
''''VB程序编制: BARDO
''''本来我想写一个只取盘动物理序列号的。但是考虑到大家学习的方便。还是将原来的代码
''''全部翻译了出来。如果你需要单一的只查一个主硬盘的序列号的程序,欢迎到本站下载。
''''
''''网站:东方热讯:http://www.easthot.net
''''邮件:sales@easthot.net
''''2003.01.23
''''*************************************************************************
Option Explicit
''''以下这一行是必须的,困为要做结构复制。而结构中有数组。所以,没有它则会错位
Option Base 0

Private Const DFP_GET_VERSION = &H74080
Private Const DFP_SEND_DRIVE_COMMAND = &H7C084
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088

''''#pragma pack(1)
Private Type TGETVERSIONOUTPARAMS   ''''{
    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(4) As Long ''''For future use.
End Type

Private Type TIDEREGS
    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 TSENDCMDINPARAMS
    cBufferSize As Long   ''''Buffer size in bytes
    irDriveRegs As TIDEREGS   ''''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.
    ''''''''BYTE  bBuffer(1)   ''''Input buffer.
End Type

Private Type TDRIVERSTATUS
    bDriverError As Byte  ''''Error code from driver, ''''or 0 if no error.
    bIDEStatus  As Byte  ''''Contents of IDE Error register.
           ''''Only valid when bDriverError ''''is SMART_IDE_ERROR.
    bReserved(1) As Byte   ''''Reserved for future expansion.
    dwReserved(1) As Long   ''''Reserved for future expansion.
End Type

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

''''下面的结构是要从另一结构复制数据过来的,所以,必须是字节数与VC的完全一致
''''而不能用兼容变量,但这里的我们还是用了兼容变量,Integer,因为此结构中这一
''''类型的的变量程序中没有用到,如果要用到,建议改为Byte类型。因为VB没有USHORT

Private Type TIDSECTOR
    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

''''/*+++
''''Global vars
''''---*/
Private vers As TGETVERSIONOUTPARAMS
Private in_data As TSENDCMDINPARAMS
Private out_data As TSENDCMDOUTPARAMS
Private h As Long
Private i As Long
Private j As Byte

Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
          (LpVersionInformation As OSVERSIONINFO) As Long

Private Const VER_PLATFORM_WIN32S = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Private Declare Function CreateFile Lib "kernel32" _
    Alias "CreateFileA" (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) _
    As Long

Private Const CREATE_NEW = 1
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2

Private Type OVERLAPPED
    Internal As Long
    InternalHigh As Long
    offset As Long
    OffsetHigh As Long
    hEvent As Long
End Type

Private Declare Function DeviceIoControl Lib "kernel32" _
    (ByVal hDevice As Long, ByVal dwIoControlCode As Long, _
    lpInBuffer As Any, ByVal nInBufferSize As Long, _
    lpOutBuffer As Any, ByVal nOutBufferSize As Long, _
    lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
         hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)


Private Sub CopyRight()
''''VC原版权代码(再发行时,请注意采用注解的方式,请不要删除的方式侵权,谢谢!)
''''****************************************************************************
'''' cerr<<endl<<"HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"<<endl
'''' cerr<<"For more information, please visit Inside Programming: http:''''lu0.126.com"<<endl
'''' cerr<<"2000.11.3"<<endl<<endl
''''****************************************************************************
Dim StrMsg As String
StrMsg = StrMsg & "直接从RING3调用API DeviceIoControl()来获取硬盘信息的VB程序 "
StrMsg = StrMsg & vbCrLf & "VC源作板权信息如下:"
StrMsg = StrMsg & vbCrLf & "***********************************************************"
StrMsg = StrMsg & vbCrLf & "HDD identifier v1.0 for WIN95/98/Me/NT/2000. written by Lu Lin"
StrMsg = StrMsg & vbCrLf & "For more information, please visit Inside Programming: http://lu0.126.com"
StrMsg = StrMsg & vbCrLf & "2000.11.3"
StrMsg = StrMsg & vbCrLf & "***********************************************************"
StrMsg = StrMsg & vbCrLf & "VB程序编制:BARDO"
StrMsg = StrMsg & vbCrLf & "网站:东方热讯:http://www.easthot.net"
StrMsg = StrMsg & vbCrLf & "邮件:sales@easthot.net"
StrMsg = StrMsg & vbCrLf & "2003.01.23"
MsgBox StrMsg
End Sub

Sub ChangeByteOrder(szStrin

[1] [2]  下一页


[Sql Server]直接从SQL语句问题贴子数据建表并生成建表语句的存…  
教程录入: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……
    咸宁网络警察报警平台