硬盘序列号的获得

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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值