硬盘序列号的获得

window98必需使用smartvsd.vxd,

 ZeroMemory(&vers,sizeof(vers));
 h=CreateFile("////.//Smartvsd",0,0,0,CREATE_NEW,0,0);
// SMARTVSD.VXD
 if (!h)
 {
  AfxMessageBox("open smartvsd.vxd failed");
  return 0;
 }

    if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0))
 {
  AfxMessageBox("DeviceIoControl failed:DFP_GET_VERSION");

  CloseHandle(h);
  return 0;
 }
 
 if (!(vers.fCapabilities&1))
 {
  AfxMessageBox("Error: IDE identify command not supported.");
  CloseHandle(h);
  return 0;
 }
 然后使用DeviceIoControl可得到序列号。

NT。使用CreateFile( //./PHYSICALDRIVEx ),再调用Deviceiocontrol

 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 (!(vers.fCapabilities&1))
  {           
   AfxMessageBox("Error: IDE identify command not supported.");
            CloseHandle(h);
            return 0;
        }
   
        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))
  {
   AfxMessageBox("is a ATAPI device, we don't detect it");
            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))
  {
            AfxMessageBox("DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA");
            CloseHandle(h);
            return 0;
        }
        phdinfo=(PIDSECTOR)out.bBuffer;
        memcpy(s,phdinfo->sModelNumber,40);
        s[40]=0;
        ChangeByteOrder(s,40);

  strData[j][0].Format("%s",s);

        memcpy(s,phdinfo->sFirmwareRev,8);
        s[8]=0;
        ChangeByteOrder(s,8);

  strData[j][1].Format("%s",s);
  
        memcpy(s,phdinfo->sSerialNumber,20);
        s[20]=0;
        ChangeByteOrder(s,20);
  strData[j][2].Format("%s",s);
  ULONG l;
  l=phdinfo->ulTotalAddressableSectors/2/1024/1024;

        CloseHandle(h);
    }

 return 1;
}

你可能感兴趣的:(硬盘序列号的获得)