C++读取硬盘的序列号

转载 2007年09月18日 09:44:00
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088
#pragma pack(1)

 

void ChangeByteOrder(PCHAR szString, USHORT uscStrSize);

typedef struct _GETVERSIONOUTPARAMS {
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;


typedef struct _IDEREGS {
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS;


typedef struct _SENDCMDINPARAMS {
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
//BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;


typedef struct _DRIVERSTATUS {
BYTE bDriverError; // Error code from driver,
// or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError
// is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;


typedef struct _SENDCMDOUTPARAMS {
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[512]; // Buffer of arbitrary length
// in which to store the data read from the drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;


typedef struct _IDSECTOR {
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR;

 

 

 

 


CString HDSNNT()
{
 
GETVERSIONOUTPARAMS vers;
SENDCMDINPARAMS in;
SENDCMDOUTPARAMS out;
HANDLE h;
DWORD i;
BYTE j;
char hd[80];
PIDSECTOR phdinfo;
char s[41];
int i_=0;


ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000

for (j=0;j<4;j++)
{

//
sprintf(hd,"////.//PhysicalDrive%d",j);


h=CreateFile(hd,
    GENERIC_READ|GENERIC_WRITE,//&brvbar;&brvbar;
             FILE_SHARE_READ|FILE_SHARE_WRITE,
    0,
    OPEN_EXISTING,
    0,
    0);

if (!h)
{
continue;
}
//发送信号
if
(!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0))
{
CloseHandle(h);
continue;
}
if (!(vers.fCapabilities&1))
{
CloseHandle(h);
}


ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));

if (j&1)
{
in.irDriveRegs.bDriveHeadReg=0xb0;
}
else
{
in.irDriveRegs.bDriveHeadReg=0xa0;
}

if (vers.fCapabilities&(16>>j))
{
continue;
}
else
{
in.irDriveRegs.bCommandReg=0xec;
}

in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;

if(!DeviceIoControl(h,
   DFP_RECEIVE_DRIVE_DATA,
   &in,
   sizeof(in),
   &out,
   sizeof(out),
   &i,
   0))
{
CloseHandle(h);
return "";
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
//显示硬盘序列号
}
CloseHandle(h);
return s;

}

void ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
{

USHORT i;
CHAR temp;

for (i = 0; i < uscStrSize; i+=2)
{
temp = szString[i];
szString[i] = szString[i+1];
szString[i+1] = temp;
}
}

 

 

 

 

    CString sss=HDSNNT();
 sss+="07";
 sss.TrimLeft();
  CString code[16]={"ad","eh","im","np","ru","vy","zc","gk",
 "pt","xb","fj","ox","wa","ei","nr","qu"};
 CString reg,stred;
 stred=sss;
 int num;
 stred.MakeLower();
 for(int i=0;i<10;i++)
 {
  char p=stred.GetAt(i);
  if(p>=48&&p<=57)
   num=p-48;
  else if(p>=97&&p<=109)
   num=p-97;
  else
   num=p-110;
  CString tmp=code[num];
  reg+=tmp; 
 }
 reg.MakeUpper();
 CString key=reg;
 CString nkey,key1,key2,key3,key4;
 GetDlgItem(IDC_EDIT1)->GetWindowText(key1);
 GetDlgItem(IDC_EDIT2)->GetWindowText(key2);
 GetDlgItem(IDC_EDIT3)->GetWindowText(key3);
 GetDlgItem(IDC_EDIT4)->GetWindowText(key4);
 nkey=key1+key2+key3+key4;
 
 if(nkey==key)
 {
  
 }
 else
 {
  MessageBox("你输入的验证码有错,请从新在输入");
 }

 

相关文章推荐

C++ 硬件信息 获取硬盘序列号

这里介绍的是获取硬盘的序列号,不是获取硬盘分区的序列号。核心是通过DeviceIoControl接口获取硬盘的版本与数据信息,很 简单。 【1】h头文件 //如果编译有问题,添加#include ...

读取硬盘序列号

#pragma hdrstop #pragma argsused #include #include #include #include "hdd.h" const WORD IDE_ATA...

获取硬盘序列号,CPU,mac地址等信息 win7下也行

这篇是我引用 http://aigudao.net/?post=107 的。比较高兴

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

C++读取硬盘序列号

本文总结C++读取硬盘序列号的资料。
  • gdnh22a
  • gdnh22a
  • 2017年02月09日 10:04
  • 999

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

C++ 获得硬盘序列号

#include  #include  #include  /**************************************/// web:itbaby.jss.cn // 作者:jav...
  • salybge
  • salybge
  • 2008年12月22日 16:36
  • 3239

通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

开发语言:C/C++支持平台:Windows实现功能:通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号下载地址:WMI_DeviceQuery.zip版本历史:V1....
  • jhqin
  • jhqin
  • 2010年05月01日 16:23
  • 31469
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:C++读取硬盘的序列号
举报原因:
原因补充:

(最多只允许输入30个字)