如何读取硬盘和光驱的系列号?(100分)

  • 主题发起人 主题发起人 ZZZ
  • 开始时间 开始时间
试一下这个函数:<br><br>function GetHDSerialNumber(Drv : ShortString): LongInt;<br>//var pp : PChar;<br>{$IFDEF WIN32}<br>var<br>&nbsp; pdw : pDWord;<br>&nbsp; mc, fl : dword;<br>{$ENDIF}<br>begin<br>&nbsp; {$IfDef WIN32}<br>&nbsp; New(pdw);<br>&nbsp; //pp := StrPCopy(pp,Copy(Drv,1,1)+':/');<br>&nbsp; GetVolumeInformation(nil,nil,0,pdw,mc,fl,nil,0);<br>&nbsp; Result := pdw^;<br>&nbsp; dispose(pdw);<br>&nbsp; {$ELSE}<br>&nbsp; Result := GetWinFlags;<br>&nbsp; {$ENDIF}<br>end;<br>
 
我测试了houyg兄的程序,好象不能真的返回序列号呢。:(<br>正好我手上有一段来自borland网页上FAQ的程序,我将它改写成了<br>一个通用函数。测试结果是正确的。(可以与chkdsk检测值比较)。<br>并且,能正常支持光驱(光盘)的检测。<br>注:如果返回值为'0000-0000',则未检测到。<br>================================================<br>function GetHDSerialNumber(Drv : String): String;<br>var<br>&nbsp; VolumeSerialNumber : DWORD;<br>&nbsp; MaximumComponentLength : DWORD;<br>&nbsp; FileSystemFlags : DWORD;<br>begin<br>&nbsp; if Drv[Length(Drv)] =':' then Drv := Drv + '/';<br>&nbsp; GetVolumeInformation(pChar(Drv),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@VolumeSerialNumber,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MaximumComponentLength,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileSystemFlags,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);<br>&nbsp; Result := IntToHex(HiWord(VolumeSerialNumber), 4) +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '-' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntToHex(LoWord(VolumeSerialNumber), 4);<br>end;<br>
 

Similar threads

后退
顶部