VC++ MFC如何获取CPU ID及硬盘的序列号?

是物理的,不是分区的,就是取得的东西必须是机子独一无二的标识”。看了网上有关于这方面资料,还是不会搞,希望有高手愿意赐教!谢谢。希望提供完整的源码,请发至dengup88... 是物理的,不是分区的,就是取得的东西必须是机子独一无二的标识”。
看了网上有关于这方面资料,还是不会搞,希望有高手愿意赐教!谢谢。
希望提供完整的源码,请发至dengup888@163.com. 谢谢!
怎么没有读取SATA硬盘序列号的?
能实现VC++ MFC 里和C#联合开发吗?
如果可以,请附上关键源码,谢谢!测试通过也是最佳答案。请高人指点!
多谢!
展开
 我来答
百度网友1b4cc0f
2010-12-07 · TA获得超过1万个赞
知道大有可为答主
回答量:4241
采纳率:42%
帮助的人:1954万
展开全部
// “获得Intel CPU ID”按钮消息处理函数
void CIntelCPUIDDlg::OnBtnCPUID()
{
unsigned long s1,s2;
unsigned char vendor_id[]="------------";//CPU提供商ID
CString str1,str2,str3;
// 以下为获得CPU ID的汇编语言指令
_asm // 得到CPU提供商信息
{
xor eax,eax // 将eax清0
cpuid // 获取CPUID的指令
mov dword ptr vendor_id,ebx
mov dword ptr vendor_id[+4],edx
mov dword ptr vendor_id[+8],ecx
}
str1.Format("%s",vendor_id);

_asm // 得到CPU ID的高32位
{
mov eax,01h
xor edx,edx
cpuid
mov s2,eax
}
str2.Format("%08X-",s2);

_asm // 得到CPU ID的低64位
{
mov eax,03h
xor ecx,ecx
xor edx,edx
cpuid
mov s1,edx
mov s2,ecx
}
str3.Format("%08X-%08X\n",s1,s2);

str2=str2+str3;
m_editVendor.SetWindowText(str1);
m_editCPUID.SetWindowText(str2);
}

// GetHDSerial.cpp: implementation of the CGetHDSerial class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GetHDSerial.h"

char m_buffer[256];
WORD m_serial[256];
DWORD m_OldInterruptAddress;
DWORDLONG m_IDTR;

// 等待硬盘空闲
static unsigned int WaitHardDiskIdle()
{
BYTE byTemp;

Waiting:
_asm
{
mov dx, 0x1f7
in al, dx
cmp al, 0x80
jb Endwaiting
jmp Waiting
}
Endwaiting:
_asm
{
mov byTemp, al
}
return byTemp;
}

//中断服务程序
void _declspec( naked )InterruptProcess(void)
{
int byTemp;
int i;
WORD temp;
//保存寄存器值
_asm
{
push eax
push ebx
push ecx
push edx
push esi
}

WaitHardDiskIdle();//等待硬盘空闲状态
_asm
{
mov dx, 0x1f6
mov al, 0xa0
out dx, al
}
byTemp = WaitHardDiskIdle(); //若直接在Ring3级执行等待命令,会进入死循环
if ((byTemp&0x50)!=0x50)
{
_asm // 恢复中断现场并退出中断服务程序
{
pop esi
pop edx
pop ecx
pop ebx
pop eax
iretd
}
}

_asm
{
mov dx, 0x1f6 //命令端口1f6,选择驱动器0
mov al, 0xa0
out dx, al
inc dx
mov al, 0xec
out dx, al //发送读驱动器参数命令
}
byTemp = WaitHardDiskIdle();
if ((byTemp&0x58)!=0x58)
{
_asm // 恢复中断现场并退出中断服务程序
{
pop esi
pop edx
pop ecx
pop ebx
pop eax
iretd
}
}
//读取硬盘控制器的全部信息
for (i=0;i<256;i++)
{
_asm
{
mov dx, 0x1f0
in ax, dx
mov temp, ax
}
m_serial[i] = temp;
}
_asm
{
pop esi
pop edx
pop ecx
pop ebx
pop eax
iretd
}
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGetHDSerial::CGetHDSerial()
{

}

CGetHDSerial::~CGetHDSerial()
{

}
// 读取硬盘序列号函数
char* CGetHDSerial::GetHDSerial()
{
m_buffer[0]='\n';
// 得到当前操作系统版本
OSVERSIONINFO OSVersionInfo;
OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx( &OSVersionInfo);
if (OSVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
{
// Windows 9x/ME下读取硬盘序列号
WORD m_wWin9xHDSerial[256];
Win9xReadHDSerial(m_wWin9xHDSerial);
strcpy (m_buffer, WORDToChar (m_wWin9xHDSerial, 10, 19));
}
else
{
// Windows NT/2000/XP下读取硬盘序列号
DWORD m_wWinNTHDSerial[256];
// 判断是否有SCSI硬盘
if ( ! WinNTReadIDEHDSerial(m_wWinNTHDSerial))
WinNTReadSCSIHDSerial(m_wWinNTHDSerial);
strcpy (m_buffer, DWORDToChar (m_wWinNTHDSerial, 10, 19));
}
return m_buffer;
}

// Windows9X/ME系统下读取硬盘序列号
void _stdcall CGetHDSerial::Win9xReadHDSerial(WORD * buffer)
{
int i;
for(i=0;i<256;i++)
buffer[i]=0;
_asm
{
push eax
//获取修改的中断的中断描述符(中断门)地址
sidt m_IDTR
mov eax,dword ptr [m_IDTR+02h]
add eax,3*08h+04h
cli
//保存原先的中断入口地址
push ecx
mov ecx,dword ptr [eax]
mov cx,word ptr [eax-04h]
mov dword ptr m_OldInterruptAddress,ecx
pop ecx
//设置修改的中断入口地址为新的中断处理程序入口地址
push ebx
lea ebx,InterruptProcess
mov word ptr [eax-04h],bx
shr ebx,10h
mov word ptr [eax+02h],bx
pop ebx
//执行中断,转到Ring 0(类似CIH病毒原理)
int 3h
//恢复原先的中断入口地址
push ecx
mov ecx,dword ptr m_OldInterruptAddress
mov word ptr [eax-04h],cx
shr ecx,10h
mov word ptr [eax+02h],cx
pop ecx
sti
pop eax
}
for(i=0;i<256;i++)
buffer[i]=m_serial[i];
}

// Windows 9x/ME系统下,将字类型(WORD)的硬盘信息转换为字符类型(char)
char * CGetHDSerial::WORDToChar (WORD diskdata [256], int firstIndex, int lastIndex)
{
static char string [1024];
int index = 0;
int position = 0;

// 按照高字节在前,低字节在后的顺序将字数组diskdata 中内容存入到字符串string中
for (index = firstIndex; index <= lastIndex; index++)
{
// 存入字中的高字节
string [position] = (char) (diskdata [index] / 256);
position++;
// 存入字中的低字节
string [position] = (char) (diskdata [index] % 256);
position++;
}
// 添加字符串结束标志
string [position] = '\0';

// 删除字符串中空格
for (index = position - 1; index > 0 && ' ' == string [index]; index--)
string [index] = '\0';

return string;
}

// Windows NT/2000/XP系统下,将双字类型(DWORD)的硬盘信息转换为字符类型(char)
char* CGetHDSerial::DWORDToChar (DWORD diskdata [256], int firstIndex, int lastIndex)
{
static char string [1024];
int index = 0;
int position = 0;

// 按照高字节在前,低字节在后的顺序将双字中的低字存入到字符串string中
for (index = firstIndex; index <= lastIndex; index++)
{
// 存入低字中的高字节
string [position] = (char) (diskdata [index] / 256);
position++;
// 存入低字中的低字节
string [position] = (char) (diskdata [index] % 256);
position++;
}
// 添加字符串结束标志
string [position] = '\0';

// 删除字符串中空格
for (index = position - 1; index > 0 && ' ' == string [index]; index--)
string [index] = '\0';

return string;
}

// Windows NT/2000/XP下读取IDE硬盘序列号
BOOL CGetHDSerial::WinNTReadIDEHDSerial(DWORD * buffer)
{
BYTE IdOutCmd [sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];
BOOL bFlag = FALSE;
int drive = 0;
char driveName [256];
HANDLE hPhysicalDriveIOCTL = 0;

sprintf (driveName, "\\\\.\\PhysicalDrive%d", drive);
// Windows NT/2000/XP下创建文件需要管理员权限
hPhysicalDriveIOCTL = CreateFile (driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);

if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)
{
GETVERSIONOUTPARAMS VersionParams;
DWORD cbBytesReturned = 0;

// 得到驱动器的IO控制器版本
memset ((void*) &VersionParams, 0, sizeof(VersionParams));
if(DeviceIoControl (hPhysicalDriveIOCTL, IOCTL_GET_VERSION,
NULL, 0, &VersionParams,
sizeof(VersionParams),
&cbBytesReturned, NULL) )
{
if (VersionParams.bIDEDeviceMap > 0)
{
BYTE bIDCmd = 0; // IDE或者ATAPI识别命令
SENDCMDINPARAMS scip;

// 如果驱动器是光驱,采用命令IDE_ATAPI_IDENTIFY, command,
// 否则采用命令IDE_ATA_IDENTIFY读取驱动器信息
bIDCmd = (VersionParams.bIDEDeviceMap >> drive & 0x10)?
IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;

memset (&scip, 0, sizeof(scip));
memset (IdOutCmd, 0, sizeof(IdOutCmd));
// 获取驱动器信息
if (WinNTGetIDEHDInfo (hPhysicalDriveIOCTL,
&scip,
(PSENDCMDOUTPARAMS)&IdOutCmd,
(BYTE) bIDCmd,
(BYTE) drive,
&cbBytesReturned))
{
int m = 0;
USHORT *pIdSector = (USHORT *)
((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;

for (m = 0; m < 256; m++)
buffer[m] = pIdSector [m];
bFlag = TRUE; // 读取硬盘信息成功
}
}
}
CloseHandle (hPhysicalDriveIOCTL); // 关闭句柄
}
return bFlag;
}

// WindowsNT/2000/XP系统下读取SCSI硬盘序列号
BOOL CGetHDSerial::WinNTReadSCSIHDSerial (DWORD * buffer)
{
buffer[0]='\n';
int controller = 0;
HANDLE hScsiDriveIOCTL = 0;
char driveName [256];
sprintf (driveName, "\\\\.\\Scsi%d:", controller);
// Windows NT/2000/XP下任何权限都可以进行
hScsiDriveIOCTL = CreateFile (driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);

if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE)
{
int drive = 0;
DWORD dummy;
for (drive = 0; drive < 2; drive++)
{
char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];
SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;
SENDCMDINPARAMS *pin =
(SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
// 准备参数
memset (buffer, 0, sizeof (buffer));
p -> HeaderLength = sizeof (SRB_IO_CONTROL);
p -> Timeout = 10000;
p -> Length = SENDIDLENGTH;
p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
strncpy ((char *) p -> Signature, "SCSIDISK", 8);
pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
pin -> bDriveNumber = drive;
// 得到SCSI硬盘信息
if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT,
buffer,
sizeof (SRB_IO_CONTROL) +
sizeof (SENDCMDINPARAMS) - 1,
buffer,
sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,
&dummy, NULL))
{
SENDCMDOUTPARAMS *pOut =
(SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
IDSECTOR *pId = (IDSECTOR *) (pOut -> bBuffer);
if (pId -> sModelNumber [0])
{
int n = 0;
USHORT *pIdSector = (USHORT *) pId;

for (n = 0; n < 256; n++)
buffer[n] =pIdSector [n];
return TRUE; // 读取成功
}
}
}
CloseHandle (hScsiDriveIOCTL); // 关闭句柄
}
return FALSE; // 读取失败
}

// Windows NT/2000/XP下读取IDE设备信息
BOOL CGetHDSerial::WinNTGetIDEHDInfo (HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP,
PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum,
PDWORD lpcbBytesReturned)
{
// 为读取设备信息准备参数
pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;
pSCIP -> irDriveRegs.bFeaturesReg = 0;
pSCIP -> irDriveRegs.bSectorCountReg = 1;
pSCIP -> irDriveRegs.bSectorNumberReg = 1;
pSCIP -> irDriveRegs.bCylLowReg = 0;
pSCIP -> irDriveRegs.bCylHighReg = 0;

// 计算驱动器位置
pSCIP -> irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum & 1) << 4);

// 设置读取命令
pSCIP -> irDriveRegs.bCommandReg = bIDCmd;
pSCIP -> bDriveNumber = bDriveNum;
pSCIP -> cBufferSize = IDENTIFY_BUFFER_SIZE;

// 读取驱动器信息
return ( DeviceIoControl (hPhysicalDriveIOCTL, IOCTL_GET_DRIVE_INFO,
(LPVOID) pSCIP,
sizeof(SENDCMDINPARAMS) - 1,
(LPVOID) pSCOP,
sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
lpcbBytesReturned, NULL) );
}
yvhpfiipfi
推荐于2017-11-23 · TA获得超过2912个赞
知道小有建树答主
回答量:880
采纳率:50%
帮助的人:693万
展开全部
  楼主你好!

  我也想知道怎么获取CPU的ID,但是,我现在有一个怎么获取硬盘物理序列号的,下面贴给你,你只需要放进一个*.cpp文件里就行了,用VC6(我也是网上找的)。

  这个是完全可以的,非常成功:

  /*+++
  HDID.CPP
  Written by Lu Lin
  http://lu0.126.com
  2000.11.3
  ---*/
  #include <windows.h>
  #include <iostream.h>
  #include <stdio.h>

  #define DFP_GET_VERSION 0x00074080
  #define DFP_SEND_DRIVE_COMMAND 0x0007c084
  #define DFP_RECEIVE_DRIVE_DATA 0x0007c088

  #pragma pack(1)
  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;

  /*+++
  Global vars
  ---*/
  GETVERSIONOUTPARAMS vers;
  SENDCMDINPARAMS in;
  SENDCMDOUTPARAMS out;
  HANDLE h;
  DWORD i;
  BYTE j;

  void CopyRight(){
  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;
  }
  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;
  }
  }

  void DetectIDE(BYTE bIDEDeviceMap){
  if (bIDEDeviceMap&1){
  if (bIDEDeviceMap&16){
  cout << "ATAPI device is attached to primary controller, drive 0. " <<endl;
  }else{
  cout << "IDE device is attached to primary controller, drive 0. " <<endl;
  }
  }
  if (bIDEDeviceMap&2){
  if (bIDEDeviceMap&32){
  cout << "ATAPI device is attached to primary controller, drive 1. " <<endl;
  }else{
  cout << "IDE device is attached to primary controller, drive 1. " <<endl;
  }
  }
  if (bIDEDeviceMap&4){
  if (bIDEDeviceMap&64){
  cout << "ATAPI device is attached to secondary controller, drive 0. " <<endl;
  }else{
  cout << "IDE device is attached to secondary controller, drive 0. " <<endl;
  }
  }
  if (bIDEDeviceMap&8){
  if (bIDEDeviceMap&128){
  cout << "ATAPI device is attached to secondary controller, drive 1. " <<endl;
  }else{
  cout << "IDE device is attached to secondary controller, drive 1. " <<endl;
  }
  }
  }

  void hdid9x(){
  ZeroMemory(&vers,sizeof(vers));
  //We start in 95/98/Me
  h=CreateFile( "\\\\.\\Smartvsd ",0,0,0,CREATE_NEW,0,0);
  if (!h){
  cout << "open smartvsd.vxd failed " <<endl;
  exit(0);
  }

  if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
  cout << "DeviceIoControl failed:DFP_GET_VERSION " <<endl;
  CloseHandle(h);
  return;
  }
  //If IDE identify command not supported, fails
  if (!(vers.fCapabilities&1)){
  cout << "Error: IDE identify command not supported. ";
  CloseHandle(h);
  return;
  }
  //Display IDE drive number detected
  DetectIDE(vers.bIDEDeviceMap);
  //Identify the IDE drives
  for (j=0;j <4;j++){
  PIDSECTOR phdinfo;
  char s[41];

  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)){
  //We don 't detect a ATAPI device.
  cout << "Drive " <<(int)(j+1) << " is a ATAPI device, we don 't detect it " <<endl;
  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)){
  cout << "DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA " <<endl;
  CloseHandle(h);
  return;
  }
  phdinfo=(PIDSECTOR)out.bBuffer;
  memcpy(s,phdinfo-> sModelNumber,40);
  s[40]=0;
  ChangeByteOrder(s,40);
  cout <<endl << "Module Number: " <<s <<endl;
  memcpy(s,phdinfo-> sFirmwareRev,8);
  s[8]=0;
  ChangeByteOrder(s,8);
  cout << "\tFirmware rev: " <<s <<endl;
  memcpy(s,phdinfo-> sSerialNumber,20);
  s[20]=0;
  ChangeByteOrder(s,20);
  cout << "\tSerial Number: " <<s <<endl;
  cout << "\tCapacity: " <<phdinfo-> ulTotalAddressableSectors/2/1024 << "M " <<endl <<endl;
  }

  //Close handle before quit
  CloseHandle(h);
  CopyRight();

  }

  void hdidnt(){
  char hd[80];
  PIDSECTOR phdinfo;
  char s[41];

  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,
  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 IDE identify command not supported, fails
  if (!(vers.fCapabilities&1)){
  cout << "Error: IDE identify command not supported. ";
  CloseHandle(h);
  return;
  }
  //Identify the IDE drives
  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)){
  //We don 't detect a ATAPI device.
  cout << "Drive " <<(int)(j+1) << " is a ATAPI device, we don 't detect it " <<endl;
  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)){
  cout << "DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA " <<endl;
  CloseHandle(h);
  return;
  }
  phdinfo=(PIDSECTOR)out.bBuffer;
  memcpy(s,phdinfo-> sModelNumber,40);
  s[40]=0;
  ChangeByteOrder(s,40);
  cout <<endl << "Module Number: " <<s <<endl;
  memcpy(s,phdinfo-> sFirmwareRev,8);
  s[8]=0;
  ChangeByteOrder(s,8);
  cout << "\tFirmware rev: " <<s <<endl;
  memcpy(s,phdinfo-> sSerialNumber,20);
  s[20]=0;
  ChangeByteOrder(s,20);
  cout << "\tSerial Number: " <<s <<endl;
  cout << "\tCapacity: " <<phdinfo-> ulTotalAddressableSectors/2/1024 << "M " <<endl <<endl;
  CloseHandle(h);
  }
  CopyRight();
  }

  void main(){
  OSVERSIONINFO VersionInfo;

  ZeroMemory(&VersionInfo,sizeof(VersionInfo));
  VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);
  GetVersionEx(&VersionInfo);

  switch (VersionInfo.dwPlatformId){
  case VER_PLATFORM_WIN32s:
  cout << "Win32s is not supported by this programm. " <<endl;
  return;
  case VER_PLATFORM_WIN32_WINDOWS:
  hdid9x();
  return;
  case VER_PLATFORM_WIN32_NT:
  hdidnt();
  return;
  }
  }

  希望能为你带来帮助,谢谢!
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
来自美国认真的兔子
2010-12-05 · TA获得超过644个赞
知道小有建树答主
回答量:550
采纳率:100%
帮助的人:426万
展开全部
我有个获得硬盘物理ID的,不过是DLL形式提供的,但可以调用里面的接口
不知道符合你的要求不?
我的建议是,你直接用它提供的DLL简单而正确。
真的你用WINDOWS API直接去得到,恐怕很难,及有可能要用到汇编的。你好好权衡吧。我这的东西我试过,确实能得到与软件无关的物理ID。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
镂心
2010-12-03 · TA获得超过648个赞
知道小有建树答主
回答量:374
采纳率:0%
帮助的人:293万
展开全部
嗯,这个有点难度!一楼加油!
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zyl102600
2010-12-10 · TA获得超过678个赞
知道小有建树答主
回答量:702
采纳率:100%
帮助的人:718万
展开全部
测试失败,请参考其他回答者的答案.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式