CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

获取硬盘物理序列号,DLL还是VXD??

楼主ttyp(@http://www.cnblogs.com/ttyp/)2001-03-31 12:36:00 在 VC/MFC / 基础类 提问

最近我想给我的软件加密,我想读硬盘的物理序列号。  
  我用过CSDN中的那个DiskSerial.dll在WIN98下总是出现非法操作,也用过http://lu0.126.com中的那个HDID.EXE,但需调用SMARTVXD.VXD觉得不太方便,有人说获得硬盘物理序列号必须在RING0下才能获得用DLL不行,到底怎样才行,请教各位高手!  
  如有源码请发到ttyp@chian.com,(立即给分)谢谢!!  
  不好意思只有这么多分能给,有分以后再给,一定。 问题点数:30、回复次数:9Top

1 楼FBStudio(飞鸟)回复于 2001-03-31 14:15:00 得分 0

参考MSDN中的函数用法  
  BOOL   GetVolumeInformation(  
      LPCTSTR   lpRootPathName,                 //   address   of   root   directory   of   the    
                                                                    //   file   system  
      LPTSTR   lpVolumeNameBuffer,           //   address   of   name   of   the   volume  
      DWORD   nVolumeNameSize,                   //   length   of   lpVolumeNameBuffer  
      LPDWORD   lpVolumeSerialNumber,     //   address   of   volume   serial   number  
      LPDWORD   lpMaximumComponentLength,  
                                                                    //   address   of   system's   maximum    
                                                                    //   filename   length  
      LPDWORD   lpFileSystemFlags,           //   address   of   file   system   flags  
      LPTSTR   lpFileSystemNameBuffer,   //   address   of   name   of   file   system  
      DWORD   nFileSystemNameSize             //   length   of   lpFileSystemNameBuffer  
  );  
     
  如果要取C盘的序列号,大概如下写  
  DWORD   dwVolumeSerialNumber;  
  BOOL   bSuccess;  
  bSuccess   =   GetVolumeInformation(  
      _T("C:\")  
      ,   NULL  
      ,   0  
      ,   &dwVolumeSerialNumber  
      ,   NULL  
      ,   NULL  
      ,   NULL  
      ,0  
  );Top

2 楼NowCan(城市浪人)回复于 2001-04-01 10:02:00 得分 5

FBStudio(飞鸟):那个是卷标,不是硬盘序列号,序列号是通过读某个端口实现的,只有在ring0下才行。Top

3 楼hhxz770(天翼.李)回复于 2001-04-05 20:15:00 得分 15

to   ttyp:  
            看了你的来信,我找的和你一样。本想发给你。见你有了没发。看来这次分数又不能得了。  
  不过diskserial,在nt   ,2000下能用。我们继续努力吧。Top

4 楼runbuff(玩水的人)回复于 2001-04-05 23:20:00 得分 10

通过MS的S.M.A.R.T.接口,我们可以直接从RING3调用API   DeviceIoControl()来获取硬盘信息.下面乃是我的例程:    
  /*+++    
  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;    
    }    
  }    
       
  Top

5 楼runbuff(玩水的人)回复于 2001-04-05 23:21:00 得分 0

我找到了上面这段代码,试过了,有效。Top

6 楼ttyp(@http://www.cnblogs.com/ttyp/)回复于 2001-04-07 10:00:00 得分 0

非常感谢以上各位朋友,获得物理序列号的问题我已找到了,和runbuff的一样,不错的!但我用vc6.0编译后在win97或me下不太稳定,运行时多按几次会的不到序列号,只能得到0,不管怎样还是给各位加点分吧!Top

7 楼ttyp(@http://www.cnblogs.com/ttyp/)回复于 2001-04-07 10:23:00 得分 0

不好意思,看错了,我用的和runbuff的不一样,他提到的就是在http://lu0.126.com上的那个,不太方便。因为给分必须一次给完,所以得过一段时间再给,以免别人看没分,不回答了!谢谢!Top

8 楼hhxz770(天翼.李)回复于 2001-04-18 19:26:00 得分 0

to   ttyp:  
        找到了,找到了就好。以后多切磋啊Top

9 楼skt642()回复于 2001-05-31 13:58:00 得分 0

77211关注!Top

相关问题

  • 硬盘物理序列号
  • 请问哪里有取硬盘物理序列号的DLL下载?
  • 分享:偶获一取硬盘物理序列号dll,要的留个邮箱
  • szjlq的取硬盘物理序列号的DLL文件,谁有,能不能发一个给我?
  • 如何修改物理硬盘的序列号? 不是卷标的序列号。
  • 请问:怎样获取硬盘的物理序列号和CPU的序列号?
  • 旧话重提:在nt/2000下怎样获取硬盘的物理序列号(如果用到了组件或dll需要有代码)up有分
  • 怎样用PB7脚本取得硬盘得物理序列号?
  • 请教(购买)软件加密--取硬盘 物理序列号
  • 免费赠送。。读取硬盘物理序列号的方法。。

关键词

  • 序列号
  • 硬盘
  • 物理
  • dll
  • null
  • lpdword
  • lu
  • byte
  • ring
  • register

得分解答快速导航

  • 帖主:ttyp
  • NowCan
  • hhxz770
  • runbuff

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo