004 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
005 |
Dialogs, StdCtrls,nb30; {重要引用} |
010 |
adapter : TAdapterStatus; |
011 |
name_buf : TNameBuffer; |
014 |
TForm1 = class (TForm) |
025 |
procedure Button1Click(Sender: TObject); |
026 |
procedure Button2Click(Sender: TObject); |
028 |
{ Private declarations } |
030 |
{ Public declarations } |
040 |
TCPUID = array [ 1..4 ] of Longint ; |
043 |
function GetIdeSerialNumber: pchar ; //獲取硬盤的出廠系列號; |
044 |
const IDENTIFY_BUFFER_SIZE = 512 ; |
046 |
TIDERegs = packed record |
048 |
bSectorCountReg: BYTE ; |
049 |
bSectorNumberReg: BYTE ; |
057 |
TSendCmdInParams = packed record |
059 |
irDriveRegs: TIDERegs; |
061 |
bReserved: array [ 0..2 ] of Byte ; |
062 |
dwReserved: array [ 0..3 ] of DWORD; |
063 |
bBuffer: array [ 0..0 ] of Byte ; |
066 |
TIdSector = packed record |
071 |
wBytesPerTrack: Word ; |
072 |
wBytesPerSector: Word ; |
073 |
wSectorsPerTrack: Word ; |
074 |
wVendorUnique: array [ 0..2 ] of Word ; |
075 |
sSerialNumber: array [ 0..19 ] of CHAR ; |
079 |
sFirmwareRev: array [ 0..7 ] of Char ; |
080 |
sModelNumber: array [ 0..39 ] of Char ; |
081 |
wMoreVendorUnique: Word ; |
088 |
wNumCurrentCyls: Word ; |
089 |
wNumCurrentHeads: Word ; |
090 |
wNumCurrentSectorsPerTrack: Word ; |
091 |
ulCurrentSectorCapacity: DWORD; |
092 |
wMultSectorStuff: Word ; |
093 |
ulTotalAddressableSectors: DWORD; |
094 |
wSingleWordDMA: Word ; |
096 |
bReserved: array [ 0..127 ] of BYTE ; |
099 |
PIdSector = ^TIdSector; |
100 |
TDriverStatus = packed record |
103 |
bReserved: array [ 0..1 ] of Byte ; |
104 |
dwReserved: array [ 0..1 ] of DWORD; |
107 |
TSendCmdOutParams = packed record |
109 |
DriverStatus: TDriverStatus; |
110 |
bBuffer: array [ 0..0 ] of BYTE ; |
114 |
cbBytesReturned: DWORD; |
115 |
SCIP: TSendCmdInParams; |
116 |
aIdOutCmd: array [ 0 ..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE- 1 )- 1 ] of Byte ; |
117 |
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd; |
119 |
procedure ChangeByteOrder( var Data; Size: Integer ); //函數(shù)中的過程 |
126 |
for I := 0 to (Size shr 1 ) - 1 do begin |
136 |
if SysUtils . Win32Platform = VER_PLATFORM_WIN32_NT then |
137 |
begin // Windows NT, Windows 2000 |
138 |
hDevice := CreateFile( '\\.\PhysicalDrive0' , GENERIC_READ or GENERIC_WRITE, |
139 |
FILE_SHARE_READ or FILE_SHARE_WRITE, nil , OPEN_EXISTING, 0 , 0 ); |
141 |
else // Version Windows 95 OSR2, Windows 98 |
142 |
hDevice := CreateFile( '\\.\SMARTVSD' , 0 , 0 , nil , Create_NEW, 0 , 0 ); |
143 |
if hDevice = INVALID_HANDLE_VALUE then Exit; |
145 |
FillChar(SCIP, SizeOf(TSendCmdInParams) - 1 , # 0 ); |
146 |
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), # 0 ); |
147 |
cbBytesReturned := 0 ; |
150 |
cBufferSize := IDENTIFY_BUFFER_SIZE; |
153 |
bSectorCountReg := 1 ; |
154 |
bSectorNumberReg := 1 ; |
155 |
bDriveHeadReg := $A0 ; |
159 |
if not DeviceIoControl(hDevice, $0007C088 , @SCIP, SizeOf(TSendCmdInParams) - 1 ,@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil ) then Exit; |
161 |
CloseHandle(hDevice); |
163 |
with PIdSector(@IdOutCmd . bBuffer)^ do |
165 |
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber)); |
166 |
( Pchar (@sSerialNumber) + SizeOf(sSerialNumber))^:= # 0 ; |
167 |
Result := Pchar (@sSerialNumber); |
170 |
//================================================================= |
173 |
FUNCTION GetCPUID : TCPUID; assembler; register; |
175 |
PUSH EBX {Save affected register} |
177 |
MOV EDI,EAX {@Resukt} |
179 |
DW $A20F {CPUID Command} |
187 |
POP EDI {Restore registers} |
191 |
function GetCPUIDStr: String ; |
196 |
Result:=IntToHex(CPUID[ 1 ], 8 )+IntToHex(CPUID[ 2 ], 8 )+IntToHex(CPUID[ 3 ], 8 )+IntToHex(CPUID[ 4 ], 8 ); |
199 |
///================================================================================== |
201 |
///取MAC(非集成網(wǎng)卡): |
203 |
function NBGetAdapterAddress(a: Integer ): string ; |
205 |
NCB: TNCB; // Netbios control block //NetBios控制塊 |
206 |
ADAPTER: TADAPTERSTATUS; // Netbios adapter status//取網(wǎng)卡狀態(tài) |
207 |
LANAENUM: TLANAENUM; // Netbios lana |
208 |
intIdx: Integer ; // Temporary work value//臨時變量 |
209 |
cRC: Char ; // Netbios return code//NetBios返回值 |
210 |
strTemp: string ; // Temporary string//臨時變量 |
215 |
// Zero control blocl |
216 |
ZeroMemory(@NCB, SizeOf(NCB)); |
217 |
// Issue enum command |
218 |
NCB . ncb_command := Chr(NCBENUM); |
219 |
cRC := NetBios(@NCB); |
220 |
// Reissue enum command |
221 |
NCB . ncb_buffer := @LANAENUM; |
222 |
NCB . ncb_length := SizeOf(LANAENUM); |
223 |
cRC := NetBios(@NCB); |
224 |
if ord(cRC) <> 0 then |
227 |
ZeroMemory(@NCB, SizeOf(NCB)); |
228 |
NCB . ncb_command := Chr(NCBRESET); |
229 |
NCB . ncb_lana_num := LANAENUM . lana[a]; |
230 |
cRC := NetBios(@NCB); |
231 |
if ord(cRC) <> 0 then |
233 |
// Get adapter address |
234 |
ZeroMemory(@NCB, SizeOf(NCB)); |
235 |
NCB . ncb_command := Chr(NCBASTAT); |
236 |
NCB . ncb_lana_num := LANAENUM . lana[a]; |
237 |
StrPCopy(NCB . ncb_callname, '*' ); |
238 |
NCB . ncb_buffer := @ADAPTER; |
239 |
NCB . ncb_length := SizeOf(ADAPTER); |
240 |
cRC := NetBios(@NCB); |
241 |
// Convert it to string |
243 |
for intIdx := 0 to 5 do |
244 |
strTemp := strTemp + InttoHex( Integer (ADAPTER . adapter_address[intIdx]), 2 ); |
249 |
//========================================================================== |
250 |
//取MAC地址(集成網(wǎng)卡和非集成網(wǎng)卡): |
252 |
function Getmac: string ; |
257 |
lanaEnum : TLanaEnum; |
259 |
strPart, strMac : string ; |
261 |
FillChar(ncb, SizeOf(TNCB), 0 ); |
262 |
ncb . ncb_command := Char (NCBEnum); |
263 |
ncb . ncb_buffer := PChar (@lanaEnum); |
264 |
ncb . ncb_length := SizeOf(TLanaEnum); |
266 |
for i := 0 to integer (lanaEnum . length)- 1 do |
268 |
FillChar(ncb, SizeOf(TNCB), 0 ); |
269 |
ncb . ncb_command := Char (NCBReset); |
270 |
ncb . ncb_lana_num := lanaEnum . lana[i]; |
273 |
FillChar(ncb, SizeOf(TNCB), 0 ); |
274 |
ncb . ncb_command := Chr(NCBAstat); |
275 |
ncb . ncb_lana_num := lanaEnum . lana[i]; |
276 |
ncb . ncb_callname := '* ' ; |
277 |
ncb . ncb_buffer := PChar (@adapt); |
278 |
ncb . ncb_length := SizeOf(TASTAT); |
280 |
if (Win32Platform = VER_PLATFORM_WIN32_NT) then |
284 |
if Netbios(@ncb) = Chr( 0 ) then |
288 |
strPart := IntToHex( integer (adapt . adapter . adapter_address[j]), 2 ); |
289 |
strMac := strMac + strPart + '-' ; |
291 |
SetLength(strMac, Length(strMac)- 1 ); |
294 |
if Netbios(@ncb) <> Chr( 0 ) then |
299 |
strPart := IntToHex( integer (adapt . adapter . adapter_address[j]), 2 ); |
300 |
strMac := strMac + strPart + '-' ; |
302 |
SetLength(strMac, Length(strMac)- 1 ); |
308 |
function PartitionString(StrV,PrtSymbol: string ): TStringList; |
312 |
result := TStringList . Create; |
313 |
iTemp := pos(PrtSymbol,StrV); |
314 |
while iTemp> 0 do begin |
315 |
if iTemp> 1 then result . Append(copy(StrV, 1 ,iTemp- 1 )); |
316 |
delete(StrV, 1 ,iTemp+length(PrtSymbol)- 1 ); |
317 |
iTemp := pos(PrtSymbol,StrV); |
319 |
if Strv<> '' then result . Append(StrV); |
322 |
function MacStr(): String ; |
329 |
Str:=TStringList . Create; |
330 |
Str:=PartitionString(Getmac, '-' ); |
331 |
for i:= 0 to Str . Count- 1 do |
332 |
MacStr:=MacStr+Str[i]; |
336 |
//============================================== |
340 |
procedure TForm1 . Button1Click(Sender: TObject); |
342 |
Edit3 . Text:=strpas(GetIdeSerialNumber); //取硬盤號 |
343 |
Edit2 . text:=GetCPUIDStr; //CPU系列號 |
344 |
edit4 . Text:=NBGetAdapterAddress( 12 ); //非集成網(wǎng)卡 |
345 |
Edit1 . text:=MacStr; //集成和非集成網(wǎng)卡 |
|