📄 在win9x-nt下获取硬盘物理序列号.mht
字号:
<TR>
<TD align=3Dleft width=3D70=20
background=3Dhttp://www.cz88.net/image/homedhbg.gif><IMG =
src=3D"http://www.cz88.net/image/homedh.gif"></TD>
<TD align=3Dleft width=3D380=20
background=3Dhttp://www.cz88.net/image/homedhbg.gif><A=20
=
href=3D"http://www.cz88.net/">=CA=D7=D2=B3</A> >> <A=20
=
href=3D"http://www.cz88.net/Class/diannao/">=B5=E7=C4=D4=BC=BC=CA=F5</A>&=
nbsp;>> <A=20
=
href=3D"http://www.cz88.net/Class/cxsj/">=B3=CC=D0=F2=C9=E8=BC=C6</A>&nbs=
p;>> <FONT=20
=
color=3Dred>=CE=C4=D5=C2=D5=FD=CE=C4</FONT></TD></TR></TBODY></TABLE></TD=
></TR>
<TR>
<TD vAlign=3Dbottom align=3Dmiddle height=3D50>
=
<H1><B>=D4=DAWin9x/NT=CF=C2=BB=F1=C8=A1=D3=B2=C5=CC=CE=EF=C0=ED=D0=F2=C1=D0=
=BA=C5</B></H1></TD></TR>
<TR>
<TD align=3Dmiddle=20
=
height=3D20>=D7=F7=D5=DF=A3=BA =C0=
=B4=D4=B4=A3=BA</TD></TR>
<TR>
<TD bgColor=3D#eeeeee height=3D3></TD></TR>
<TR>
<TD height=3D5></TD></TR>
<TR>
<TD vAlign=3Dtop height=3D100>#include =
<WinIOCtl.h><BR>#include=20
<stdio.h><BR><BR>#pragma=20
=
inline<BR>//-------------------------------------------------------------=
--------------<BR>//=20
IDE NT/2000/XP=D7=A8=D3=C3=B1=E4=C1=BF<BR>#define=20
=
GETVERSIONOUTPARAMS GETVERSIONINPARAMS<BR>#d=
efine=20
=
DFP_GET_VERSION SMAR=
T_GET_VERSION<BR>#define=20
=
DFP_SEND_DRIVE_COMMAND SMART_SEND_DRIVE_COMMAND<BR>#define=20
=
DFP_RCV_DRIVE_DATA SMART_RCV_DRIVE_DAT=
A<BR><BR>const=20
WORD IDE_ATAPI_IDENTIFY =3D 0xA1; //=20
=B6=C1=C8=A1ATAPI=C9=E8=B1=B8=B5=C4=C3=FC=C1=EE<BR>const =
WORD IDE_ATA_IDENTIFY =3D=20
0xEC; // =
=B6=C1=C8=A1ATA=C9=E8=B1=B8=B5=C4=C3=FC=C1=EE<BR><BR>const int =
MAX_IDE_DRIVES=20
=3D 4;<BR><BR>// SCSI=D7=A8=D3=C3=B1=E4=C1=BF<BR>const DWORD =
=
FILE_DEVICE_SCSI &nb=
sp; =3D=20
0x0000001B;<BR>const DWORD IOCTL_SCSI_MINIPORT_IDENTIFY =3D=20
((FILE_DEVICE_SCSI << 16) + 0x0501);<BR>const DWORD=20
=
IOCTL_SCSI_MINIPORT =
=3D=20
0x0004D008; // see NTDDSCSI.H for definition<BR>const DWORD=20
SENDIDLENGTH =3D sizeof(SENDCMDOUTPARAMS) +=20
IDENTIFY_BUFFER_SIZE;<BR><BR>typedef struct=20
_SRB_IO_CONTROL<BR>{<BR> ULONG=20
HeaderLength;<BR> UCHAR=20
Signature[8];<BR> ULONG=20
Timeout;<BR> ULONG=20
ControlCode;<BR> ULONG=20
ReturnCode;<BR> ULONG=20
Length;<BR>}SRB_IO_CONTROL, *PSRB_IO_CONTROL;<BR><BR>//=20
=B6=C1=C8=A1=B5=C4=D6=F7=BA=AF=CA=FD<BR>void __fastcall =
ReadPhysicalDrive(TStrings *pSerList,=20
TStrings *pModeList);<BR><BR>// =
=B8=A8=D6=FA=BA=AF=CA=FD<BR>char *__fastcall=20
ConvertToString(DWORD dwDiskData[256], int nFirstIndex, int=20
nLastIndex);<BR>// NT/2000/XP=BA=AF=CA=FD<BR>void __fastcall =
ReadPhysicalDriveOnNT(TStrings *pSerList, TStrings=20
*pModeList);<BR>bool __fastcall DoIdentify(HANDLE=20
hPhysicalDriveIOCTL, PSENDCMDINPARAMS=20
=
pSCIP,<BR> PSENDCMDOUTPARA=
MS=20
pSCOP, BYTE=20
=
btIDCmd,<BR> BYTE=20
btDriveNum, PDWORD lpcbBYTEsReturned);<BR>// Windows =
9X=BA=AF=CA=FD<BR>void=20
__fastcall ReadPhysicalDriveOnW9X(TStrings *pSerList, =
TStrings=20
*pModeList);<BR>void __fastcall =
ReadPhysicalDriveOnW9X_Ring0(bool=20
IsFirst, WORD=20
=
BaseAddress,<BR> BYTE=20
MoS, bool &IsIDEExist, bool &IsDiskExist, WORD=20
*OutData);<BR><BR>// SCSI=B6=C1=C8=A1=BA=AF=CA=FD(for =
NT/2000/XP)<BR>String __fastcall=20
=
ReadIDEDriveAsScsiDriveOnNT();<BR>//-------------------------------------=
--------------------------------------<BR>//=20
ReadPhysicalDrive<BR>void __fastcall =
ReadPhysicalDrive(TStrings=20
*pSerList, TStrings=20
=
*pModeList)<BR>{<BR> switch(Win32Platform)<BR>&nbs=
p; {<BR> =
case=20
=
VER_PLATFORM_WIN32_WINDOWS:<BR> =
ReadPhysicalDriveOnW9X(pSerList,=20
=
pModeList);<BR> &nbs=
p; break;<BR> c=
ase=20
=
VER_PLATFORM_WIN32_NT:<BR>  =
; ReadPhysicalDriveOnNT(pSerList,=20
=
pModeList);<BR> &nbs=
p; break;<BR> d=
efault:<BR> &n=
bsp; break;<BR> }<BR>}<BR>//-----------------=
----------------------------------------------------------<BR>//=20
ConvertToString<BR>char *__fastcall ConvertToString(DWORD=20
dwDiskData[256], int nFirstIndex, int=20
nLastIndex)<BR>{<BR> static char=20
szResBuf[1024];<BR> int nIndex =3D=20
0;<BR> int nPosition =3D=20
0;<BR><BR> // Each integer has two =
characters=20
stored in it backwards<BR> for(nIndex =
=3D=20
nFirstIndex; nIndex <=3D nLastIndex;=20
=
nIndex++)<BR> {<BR> &=
nbsp; //=20
Get high BYTE for 1st=20
=
character<BR> szResBuf[nPo=
sition]=20
=3D (char)(dwDiskData[nIndex] /=20
=
256);<BR> nPosition++;<BR>=
<BR> //=20
Get low BYTE for 2nd=20
=
character<BR> szResBuf[nPo=
sition]=20
=3D (char)(dwDiskData[nIndex] %=20
=
256);<BR> nPosition++;<BR>=
}<BR><BR> //=20
End the =
string<BR> szResBuf[nPosition] =3D=20
'\0';<BR><BR> // Cut off the trailing =
blanks<BR> for(nIndex =3D nPosition - =
1; nIndex=20
> 0 && ' ' =3D=3D szResBuf[nIndex];=20
=
nIndex--)<BR> szResBuf[nIn=
dex]=20
=3D '\0';<BR><BR> return=20
=
szResBuf;<BR>}<BR>//-----------------------------------------------------=
----------------------<BR>//=20
Winndows NT4/2000/XP=20
=
=B4=FA=C2=EB<BR>//-------------------------------------------------------=
--------------------<BR>//=20
ReadPhysicalDriveOnNT<BR>void __fastcall=20
ReadPhysicalDriveOnNT(TStrings *pSerList, TStrings=20
*pModeList)<BR>{<BR> //=20
=CA=E4=B3=F6=B2=CE=CA=FD<BR> BYTE=20
btIDOutCmd[sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - =
1];<BR><BR> for(int nDrive=3D0; =
nDrive <=20
MAX_IDE_DRIVES;=20
=
nDrive++)<BR> {<BR> &=
nbsp; HANDLE=20
=
hPhysicalDriveIOCTL;<BR> c=
har=20
=
szDriveName[32];<BR><BR> s=
printf(szDriveName,=20
"\\\\.\\PhysicalDrive%d",=20
=
nDrive);<BR> hPhysicalDriv=
eIOCTL=20
=3D=20
=
CreateFile(szDriveName,<BR> &nbs=
p;  =
; GENERIC_READ=20
|=20
=
GENERIC_WRITE,<BR> &=
nbsp; &n=
bsp; FILE_SHARE_READ=20
| FILE_SHARE_WRITE,=20
=
NULL,<BR> &nbs=
p;  =
; OPEN_EXISTING,=20
0,=20
=
NULL);<BR><BR> if(hPhysica=
lDriveIOCTL=20
!=3D=20
=
INVALID_HANDLE_VALUE)<BR> =
{<BR> &n=
bsp;DWORD=20
dwBytesReturned =3D=20
=
0;<BR> &=
nbsp;GETVERSIONOUTPARAMS=20
=
gvopVersionParams;<BR><BR>  =
; //=20
Get the version, etc of PhysicalDrive=20
=
IOCTL<BR> &nbs=
p; ZeroMemory(&gvopVersionParams,=20
=
sizeof(GETVERSIONOUTPARAMS));<BR><BR> =
if(!DeviceIoControl(hPhysicalDriveIOC=
TL,=20
=
DFP_GET_VERSION,<BR>  =
; NULL, =
0, &gvopVersionParams,=20
=
sizeof(gvopVersionParams),<BR> &=
nbsp; &n=
bsp;&dwBytesReturned,=20
=
NULL))<BR> &nb=
sp; {<BR>  =
; continue;<BR>  =
; }<BR><BR> &nb=
sp; if(gvopVersionPa=
rams.bIDEDeviceMap=20
>=20
=
0)<BR> &=
nbsp;{<BR> &nb=
sp; //=20
IDE or ATAPI IDENTIFY=20
=
cmd<BR> =
BYTE=20
btIDCmd =3D=20
=
0;<BR> &=
nbsp; SENDCMDINPARAMS=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -