代码???

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);var  SerialNum : pdword;  a, b : dword;  Buffer  : array [0..255] of char;begin  if GetVolumeInformation('c:\', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then    Label1.Caption := IntToStr(SerialNum^);end; 
      

  2.   

    不好意思,刚刚贴的是获取卷标下面的文章你看看,或许有帮助以下文章来自别处。标 题:转载 软件诊所论坛:李伟帖的一篇《关于硬盘序列号的探讨! 》。以前有人问过这方面的问题 (4千字)发信人:看雪时 间:2000-6-27 19:31:08 详细信息:From: "Wang Xianbing"  Subject: 关于硬盘序列号的探讨! Newsgroups: programr.china 大家好: 近来在CFIDO和E-mail中一直有朋友询问关于如何能在Windows下用VB来 获取硬盘序列号的问题, 因为在VB的for Windows中版本中没有了端口存取 函数, 所以就写了一个HDIDE16.DLL的东东, 放在主页上免费发放, 并且 HDIDE32版本的即将出台, 孰知却遭到 XXX 肆意践踏, 理由如下: ---- CUT ---- WX> 好久一来, 一直未能发现有用VB来获取硬盘序列号的东东, WX> 以致于VB的程序 不能得到很好的保护, 所以昨天做了个HDIDE16.DLL, RT> 太烦了吧! RT> 不是我想给你泼冷水,你的WINAPI知识有点欠乏! RT> 取计算机硬盘序列号及卷名的函数是: RT> 这个老早我就用了. RT> 加密方法很多种,也不一定用硬盘序列号. RT> 可惜不能说. :))) --- CUT --- 对此, 我表示强烈的抗议, 并且为避免由此引起的误导, 特将基本的常识区 分如下, 附有完整的对比源程序: 关于盘序列号有两种: 硬盘序列号: 英文名 Hard Disk Serial Number, 该号是出厂时生产厂家为 区别产品而设置的, 是唯一的, 是只读的, 利用硬盘序列号的 加密往往是利用其唯一和只读的特性, 大多是针对有序列号的 IDE HDD而言, 对于没有序列号或SCSI HDD硬盘则无能为力, 这也是利用它进行加密的局限性. 卷的序列号: 英文名 Volume Serial Number, 该号既可指软磁盘要得, 如: A:盘和B:盘的, 又可以指硬盘的逻辑盘, 如: C:, D:...的, 是高级格式化时随机产生的, 是可以修改的, 所以利用其进行 加密, 其唯一性还可, 而其可修改性对于安全而言就大打折扣 了. 那么如何获得它们呢? 这要视不同的平台而论, 核心实现方法如下: DOS平台 Windows 3.X Windows 9.X 硬盘序列号: 端口I/O 端口I/O Ring0级I/O 卷的序列号: 中断调用 WINAPI WINAPI 为方便大家验证, 特贴如下两程序用TC或BC编译后运行在DOS下即可: /* 程序1: 获得IDE硬盘C的序列号 */ #include  #include  #include  #include  #include  char *getascii (unsigned int in_data [], int off_start, int off_end); void main (void) { unsigned int dd [256]; /* DiskData */ unsigned int dd_off; /* DiskData offset */ while (inp (0x1F7) != 0x50) /* Wait for controller not busy */ ; outp (0x1F6, 0xA0); /* Get first/second drive */ outp (0x1F7, 0xEC); /* Get drive info data */ while (inp (0x1F7) != 0x58) /* Wait for data ready */ ; for (dd_off = 0; dd_off != 256; dd_off++) /* Read "sector" */ dd [dd_off] = inpw (0x1F0); printf ("The Serial Number Hard Disk [C] is %s", getascii (dd, 10, 19)); } char *getascii (unsigned int in_data [], int off_start, int off_end) { static char ret_val [255]; int loop, loop1; for (loop = off_start, loop1 = 0; loop <= off_end; loop++) { ret_val [loop1++] = (char) (in_data [loop] / 256); /* Get High byte */ ret_val [loop1++] = (char) (in_data [loop] % 256); /* Get Low byte */ } ret_val [loop1] = ""; /* Make sure it ends in a NULL character */ return (ret_val); } /* 程序2: 获得逻辑盘C的序列号 */ #include  #include  #include  #include  void main(void) { char serial_no[10]; union REGS r; struct SREGS s; unsigned sno1, sno2; r.x.ax = 0x6900; r.h.bl = 3; /* A:=1, B:=2, C:=3 etc. */ segread(&s); intdosx(&r, &r, &s); if (r.x.cflag) *serial_no = ""; else { sno2 = *((unsigned far *)MK_FP(s.ds, r.x.dx+2)); sno1 = *((unsigned far *)MK_FP(s.ds, r.x.dx+4)); sprintf(serial_no, "%04X-%04X ", sno1, sno2); } printf("The Serial Number of Login Disk [C] is %s", serial_no ); } 在Windows 3.X中: 硬盘序列号: 使用端口I/O即可, 将以上程序稍加修改并用VC或BC做成DLL 即可在VB中调用, 本人就是这样做的. 卷的序列号: 用那位朋友所说的WINAPI函数GetVolumeInformation即可. 在Windows 9.X中:  还可以访问http://www.csdn.net/cnshare/soft/soft4806.shtm  
     
      

  3.   

    function GetHDSerialNumber: LongInt;    //得到硬盘序列号
    {$IFDEF WIN32}
    var 
      pdw : pDWord; 
      mc, fl : dword; 
    {$ENDIF} 
    begin 
      {$IfDef WIN32} 
      New(pdw); 
      GetVolumeInformation('c:\',nil,0,pdw,mc,fl,nil,0); 
      Result := pdw^;
      dispose(pdw); 
      {$ELSE}
      Result := GetWinFlags;
      {$ENDIF} 
    end;我常用没问题~
      

  4.   

    http://www.csdn.net/cnshare/soft/15/15890.shtm