300分大放血,关于读取主板,硬盘,CPU等信息的程序!(讲废话者免进)(300分)

  • 主题发起人 lio_cheng
  • 开始时间
L

lio_cheng

Unregistered / Unconfirmed
GUEST, unregistred user!
我想了解如何读取一些硬件信息的知识,希望各位高手赐教!
希望各位能讲的明白一点!运行通过马上给分!(只要不是别人已经讲过的)
 
获得Intel CPU的信息
下面这个函数会返回一个字符串列表及特性集合,这个函数只对Intel 486及以上的CPU有效。其他CPU将返回[cpuNonIntel] 或 [cpuNoCPUID].

用法:

GetCpuFeatures(memo1.Lines);

支持的特性
---------------------------------------
CPU Family 6
CPU Model 7
CPU Stepping 3
On-Chip FPU
VirtualMode Extensions
Debugging Extensions
Page Size Extensions
Time Stamp Counter
Model Specific Registers
Physical Address Extensions
Machine Check Extensions
CMPXCHG8B Instruction
Fast System Call
Memory Type Range Registers
Page Global Enable
Machine Check Architecture
Conditional Move Instruction
Page Attribute Table
32 Bit Page Size Extension
Intel MMX Technology
Fast Floating Point Save and Restore
Streaming SIMD Extensions

unit Unit2;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;

type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations } end;

TCpuFeature = (cpuNoCPUID,cpuNonIntel,cpuOnChipFPU,
cpuVirtualModeExtensions,cpuDebuggingExtensions,
cpuPageSizeExtensions,cpuTimeStampCounter,
cpuModelSpecificRegisters,cpuPhysicalAddressExtensions,
cpuMachineCheckExtensions,cpuCMPXCHG8B,cpuOnChipAPIC,
cpuFastSystemCall,cpuMemoryRangeRegisters,cpuPageGlobalEnable,
cpuMachineCheckArchitecture,cpuConditionalMoveInstruction,
cpuPageAttributeTable,cpu32bitPageSzExtension,
cpuProcessorSerialNum,cpuMMXTechnology,cpuFastFloatingPoint,
cpuSIMDExtensions);

TCpuFeatures = set of TCpuFeature;

function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;

var Form2: TForm2;
implementation
{$R *.DFM}

function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;
const
FPU_FLAG = $0001;
VME_FLAG = $0002;
DE_FLAG = $0004;
PSE_FLAG = $0008;
TSC_FLAG = $0010;
MSR_FLAG = $0020;
PAE_FLAG = $0040;
MCE_FLAG = $0080;
CX8_FLAG = $0100;
APIC_FLAG = $0200;
SEP_FLAG = $0800;
MTRR_FLAG = $1000;
PGE_FLAG = $2000;
MCA_FLAG = $4000;
CMOV_FLAG = $8000;
PAT_FLAG = $10000;
PSE36_FLAG = $20000;
PSNUM_FLAG = $40000;
MMX_FLAG = $800000;
FXSR_FLAG = $1000000;
SIMD_FLAG = $2000000;

var IsIntel : boolean;
VendorID : array [0..12] of char;
IntelID : array [0..12] of char;
FeaturesFlag,CpuSignature : DWord;
Temp : DWord;
RetVar : TCpuFeatures;
CpuType : byte;

procedure CheckFeature(FeatureFlag : DWord;
const Item : string;
cpuFeatureType : TCpuFeature);
begin
if FeaturesFlag and FeatureFlag = FeatureFlag then begin
if FeatureList <> nil then FeatureList.Add(Item);
include(RetVar,cpuFeatureType);
end;
end;

begin
RetVar := [];
if FeatureList <> nil then FeatureList.Clear;
IsIntel := false;
IntelId := 'GenuineIntel'#0;
VendorID := '------------'#0;

try
asm

//确认是否支持Intel CPUID调用
push ebx
push esi
push edi
mov eax,0 // Set up for CPUID instruction
db 00fh // CPUID - Get Vendor and check INTEL
db 0a2h
mov dword ptr VendorId,ebx
mov dword ptr VendorId[+4],edx
mov dword ptr VendorId[+8],ecx
cmp dword ptr IntelId,ebx //检查是否是Intel CPU
jne @@EndCPUID
cmp dword ptr IntelId[+4],edx
jne @@EndCPUID
cmp dword ptr IntelId[+8],ecx
jne @@EndCPUID // 非Intel CPU

mov byte ptr IsIntel,1 // Set IsIntel to true
cmp eax,1 // Ensure 1 is valid input for CPUID
jl @@EndCPUID // Else jump to end

mov eax,1
db 00fh // CPUID - Get features,family etc.
db 0a2h
mov CpuSignature,eax
mov FeaturesFlag,edx
shr eax,8 // Isolate family
and eax,0fh
mov byte ptr CpuType,al // Set cputype with family

@@EndCPUID :

pop edi // 恢复寄存器
pop esi
pop ebx
end;

// 检查特性掩码
if IsIntel then begin
if FeatureList <> nil then begin
FeatureList.Add('CPU Family ' + IntToStr(CpuType));
Temp := (CpuSignature shr 4) and $0f;
FeatureList.Add('CPU Model ' + IntToStr(Temp));
Temp := CpuSignature and $0f;
FeatureList.Add('CPU Stepping ' + IntToStr(Temp));
end;

CheckFeature(FPU_FLAG,'On-Chip FPU',cpuOnChipFPU);
CheckFeature(VME_FLAG,
'VirtualMode Extensions',cpuVirtualModeExtensions);
CheckFeature(DE_FLAG,'Debugging Extensions',cpuDebuggingExtensions);
CheckFeature(PSE_FLAG,'Page Size Extensions',cpuPageSizeExtensions);
CheckFeature(TSC_FLAG,'Time Stamp Counter',cpuTimeStampCounter);
CheckFeature(MSR_FLAG,
'Model Specific Registers',cpuModelSpecificRegisters);
CheckFeature(PAE_FLAG,
'Physical Address Extensions',
cpuPhysicalAddressExtensions);
CheckFeature(MCE_FLAG,
'Machine Check Extensions',cpuMachineCheckExtensions);
CheckFeature(CX8_FLAG,'CMPXCHG8B Instruction',cpuCMPXCHG8B);
CheckFeature(APIC_FLAG,'On Chip APIC',cpuOnChipAPIC);
CheckFeature(SEP_FLAG,'Fast System Call',cpuFastSystemCall);
CheckFeature(MTRR_FLAG,
'Memory Type Range Registers',cpuMemoryRangeRegisters);
CheckFeature(PGE_FLAG,'Page Global Enable',cpuPageGlobalEnable);
CheckFeature(MCA_FLAG,
'Machine Check Architecture',cpuMachineCheckArchitecture);
CheckFeature(CMOV_FLAG,
'Conditional Move Instruction',
cpuConditionalMoveInstruction);
CheckFeature(PAT_FLAG,'Page Attribute Table',cpuPageAttributeTable);
CheckFeature(PSE36_FLAG,
'32 Bit Page Size Extension',cpu32BitPageSzExtension);
CheckFeature(PSNUM_FLAG,
'Processor Serial Number',cpuProcessorSerialNum);
CheckFeature(MMX_FLAG,'Intel MMX Technology',cpuMMXTechnology);
CheckFeature(FXSR_FLAG,
'Fast Floating Point Save and Restore',
cpuFastFloatingPoint);
CheckFeature(SIMD_FLAG,'Streaming SIMD Extensions',cpuSIMDExtensions);
end
else begin
if FeatureList <> nil then
FeatureList.Add('Non-Intel or >486 Chip - Features Unknown');
include(RetVar,cpuNonIntel);
end;
except
if FeatureList <> nil then FeatureList.Add('No CPUID Support');
include(RetVar,cpuNoCPUID);
end;

Result := RetVar;
end;

end.

要得到显示器的分辨率,由下列程序得到:
var
x:longint;
a:string;
begin
x := GetSystemMetrics(SM_CXSCREEN);
Str(x,a);
Label1.Caption := '显示器水平分辨率' + a;
x := GetSystemMetrics(SM_CYSCREEN);
Str(x,a);
Label2.Caption := '显示器垂直分辨率' + a;
end;
内存信息
Structure of TMemoryStatus:

TMemoryStatus = record
dwLength: DWORD;
dwMemoryLoad: DWORD;
dwTotalPhys: DWORD;
dwAvailPhys: DWORD;
dwTotalPageFile: DWORD;
dwAvailPageFile: DWORD;
dwTotalVirtual: DWORD;
dwAvailVirtual: DWORD;

Function called to populate TMemoryStatus:

procedure GlobalMemoryStatus(var lpBuffer: TMemoryStatus); stdcall;

WINAPI help for said function:

VOID GlobalMemoryStatus(
// pointer to the memory status structure
LPMEMORYSTATUS lpBuffer
);

Code for populating a TMemo with Information about system resources:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
MemoryStatus: TMemoryStatus;

begin

Memo1.Lines.Clear;

MemoryStatus.dwLength := SizeOf(MemoryStatus);

GlobalMemoryStatus(MemoryStatus);

with MemoryStatus do
begin
// Size of MemoryStatus record
Memo1.Lines.Add(IntToStr(dwLength) +
' Size of ''MemoryStatus'' record');
// Per-Cent of Memory in use by your system
Memo1.Lines.Add(IntToStr(dwMemoryLoad) +
'% memory in use');
// The amount of Total Physical memory allocated to your system.
Memo1.Lines.Add(IntToStr(dwTotalPhys) +
' Total Physical Memory in bytes');
// The amount available of physical memory in your system.
Memo1.Lines.Add(IntToStr(dwAvailPhys) +
' Available Physical Memory in bytes');
// The amount of Total Bytes allocated to your page file.
Memo1.Lines.Add(IntToStr(dwTotalPageFile) +
' Total Bytes of Paging File');
// The amount of available bytes in your page file.
Memo1.Lines.Add(IntToStr(dwAvailPageFile) +
' Available bytes in paging file');
// The amount of Total bytes allocated to this program
// (generally 2 gigabytes of virtual space).
Memo1.Lines.Add(IntToStr(dwTotalVirtual) +
' User Bytes of Address space');
// The amount of avalable bytes that is left to your program to use.
Memo1.Lines.Add(IntToStr(dwAvailVirtual) +
' Available User bytes of address space');
end; // with
end; // procedure

end.

cpu速度
program CpuSpeed;
uses SysUtils, Windows, Dialogs;
function GetCpuSpeed: Comp;
var
t: DWORD;
mhi, mlo, nhi, nlo: DWORD;
t0, t1, chi, clo, shr32: Comp;
begin
shr32 := 65536;
shr32 := shr32 * 65536;
t := GetTickCount;
while t = GetTickCount do begin end;
asm
DB 0FH
DB 031H
mov mhi,edx
mov mlo,eax
end;
while GetTickCount < (t + 1000) do begin end;
asm
DB 0FH
DB 031H
mov nhi,edx
mov nlo,eax
end;
chi := mhi; if mhi < 0 then chi := chi + shr32;
clo := mlo; if mlo < 0 then clo := clo + shr32;
t0 := chi * shr32 + clo;
chi := nhi; if nhi < 0 then chi := chi + shr32;
clo := nlo; if nlo < 0 then clo := clo + shr32;
t1 := chi * shr32 + clo;
Result := (t1 - t0) / 1E6;
end;
begin
MessageDlg(Format('%.1f MHz', [GetCpuSpeed]), mtConfirmation, [mbOk], 0);
end.




--------------------------------------------------------------------------------



function GetCPUSpeed: Double;
const
DelayTime = 500; // measure time in ms
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);

SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;

SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);


Result := TimerLo / (1000.0 * DelayTime);
end;





--------------------------------------------------------------------------------

function RDTSC : Int64; assembler;
asm
db $0F, $31 // opcode for RDTSC
end;

function RDQPC : Int64;
begin
QueryPerformanceCounter(result);
end;

function CPUSpeed : Integer;
var
f,tsc,pc : Int64;
begin
if QueryPerformanceFrequency(f) then
begin
Sleep(0);
pc := RDQPC;
tsc := RDTSC;
Sleep(100);
pc := RDQPC-pc;
tsc := RDTSC-tsc;
result := round(tsc*f/(pc*1000000));
end
else
result := -1;
end;
  一、 用GetDriveType函数获取磁盘信息
  Lbl_DriveType:Tlabel;
  DriveType:WORD; //定义驱动器类型变量
  DriveType:=GetDriveType(RootPathName); //获得RootPathName所对应的磁盘驱动器信息
  case DriveType of
  DRIVE_REMOVABLE:Lbl_DriveType.Caption:= '软盘驱动器';
  DRIVE_FIXED : Lbl_DriveType.Caption:= '硬盘驱动器';
  DRIVE_REMOTE: Lbl_DriveType.Caption:= '网络驱动器';
  DRIVE_CDROM: Lbl_DriveType.Caption:= '光盘驱动器';
  DRIVE_RAMDISK: Lbl_DriveType.Caption:= '内存虚拟盘';
  end; //将该磁盘信息显示在Lbl_DriveType中
  二、 用GlobalMemoryStatus函数获取内存使用信息
  MemStatus: TMEMORYSTATUS; //定义内存结构变量
  Lbl_Memory:Tlabel;
  MemStatus.dwLength := size of(TMEMORYSTATU?
S);
  GlobalMemoryStatus(MemStatus); //返回内存使用信息
   Lbl_Memory.Caption := format('共有内存: %d KB 可用内存: %dKB',[MemStatus.dwAvailPhys div 1024,MemStatus.dwTotalPhys div 1024]);
  //将内存信息显示在Lbl_Memory中
  三、 用GetSystemInfo函数获取CPU信息
  SysInfo: TSYSTEMINFO;
  Lbl_CPUName:Tlabel;
  GetSystemInfo(SysInfo);//获得CPU信息
  case SysInfo.dwProcessorType of
  PROCESSOR_INTEL_386:Lbl_CPUName.Caption:=format('%d%s',[SysInfo.dwNumber Of Processors,'Intel80386']);
  PROCESSOR_INTEL_486:Lbl_CPUName.Caption:=format('%d%s',[SysInfo.dwNumber Of Processors, 'Intel 80486']);
  PROCESSOR_INTEL_PENTIUM:Lbl_CPUName.Caption:=format('%d%s',[SysInfo.dwNum
berOfProcessors, 'Intel Pentium']);
  PROCESSOR_MIPS_R4000:Lbl_CPUName.Caption:=format('%d%s',[SysInfo.dwNumberOfProcessors, 'MIPS R4000']);
  PROCESSOR_ALPHA_21064:Lbl_CPUName.Caption:=format('%d%s',[SysInfo.dwNumberOfProcessors, 'ALPHA 21064']);
  end;//把CPU信息显示在Lbl_CPUName中。(陕西 杨波)
 
有一个X2000控件包,一切都可以搞定!
 
第一位高手,讲的太高深了!我根本无法拿去应用!有相应的程序让我参考吗?
第二位“高手”讲的也太笼统了吧?你有这样的控件包吗?可不可以发给我?
 
结果放在Memo1中。
procedure TForm1.Button1Click(Sender: TObject);
var
systeminfo: SYSTEM_INFO;
memory: MEMORYSTATUS;
sector,byte,cluster,free: DWORD;
freespace,totalspace: longint;
CDtype: UINT;
name: CHAR;
drvname: string;
volname,filesysname: PCHAR;
sno,maxl,fileflag: DWORD;
begin
Memo1.Lines.Clear();
//获得CPU型号
GetSystemInfo(systeminfo);
Memo1.Lines.Add('您的CPU类型是:' + inttostr(systeminfo.dwProcessorType));

//获得内存状态
memory.dwLength := sizeof(memory); //初始化
GlobalMemoryStatus(memory);
Memo1.Lines.Add('您的物理内存是(' + inttostr(integer(memory.dwTotalPhys div 1024 div 1024)) + 'MB)。');
Memo1.Lines.Add('其中可用内存是(' + inttostr(integer(memory.dwTotalPhys div 1024)) + 'KB)。');

//获得C盘可用空间
GetDiskFreeSpace('C:', LPDWORD(@sector)^, LPDWORD(@byte)^, LPDWORD(@free)^, LPDWORD(@cluster)^); //获得返回参数
totalspace := cluster * byte * sector div 1024 div 1024; //计算总容量
freespace := free * byte * sector div 1024 div 1024; //计算可用空间
Memo1.Lines.Add('C盘总空间(' + inttostr(integer(totalspace)) + 'MB)。');
Memo1.Lines.Add('C盘可用空间(' + inttostr(integer(freespace)) + 'MB)。');

//检测CD-ROM,是否有光盘
GetMem(volname, 255);
GetMem(filesysname, 100);
for name :='C' to 'Z' do//循环检测A~Z
begin
drvname := name + ':';
CDtype := GetDriveType(PCHAR(@drvname[1])); //获得磁盘类型
if (CDtype = DRIVE_CDROM) then
begin
Memo1.Lines.Add('您的光驱盘符为[' + drvname + ']');
volname^ := Chr(0);
filesysname^ := Chr(0);
if ( not (GetVolumeInformation(PCHAR(@drvname[1]), volname, 250, LPDWORD(@sno), LPDWORD(@maxl)^, LPDWORD(@fileflag)^, filesysname,100))) then
Memo1.Lines.Add(drvname + '驱中没有发现光盘') //如果返回值为假
else //如果返回值为真
begin
Memo1.Lines.Add (drvname + '驱中光盘卷标为: [' + String(volname) + ']');
Memo1.Lines.Add (drvname + '驱中光盘序号为: [' + inttostr(sno) + ']');
end;
end;
end;
FreeMem(volname);
FreeMem(filesysname)
end;

 
有一个带原码的免费组件,可以读机器信息,如硬盘ID等。
3M大小,
如果,需要可以发给你
 
class Win32_Processor : CIM_Processor
{
uint16 AddressWidth;
uint16 Architecture;
uint16 Availability;
string Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
uint16 CpuStatus;
string CreationClassName;
uint32 CurrentClockSpeed;
uint16 CurrentVoltage;
uint16 DataWidth;
string Description;
string DeviceID;
boolean ErrorCleared;
string ErrorDescription;
uint32 ExtClock;
uint16 Family;
datetime InstallDate;
uint32 L2CacheSize;
uint32 L2CacheSpeed;
uint32 LastErrorCode;
uint16 Level;
uint16 LoadPercentage;
string Manufacturer;
uint32 MaxClockSpeed;
string Name;
string OtherFamilyDescription;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
string ProcessorId;
uint16 ProcessorType;
uint16 Revision;
string Role;
string SocketDesignation;
string Status;
uint16 StatusInfo;
string Stepping;
string SystemCreationClassName;
string SystemName;
string UniqueId;
uint16 UpgradeMethod;
string Version;
uint32 VoltageCaps;
};
上面是有关 CPU 的,内存、IDE、PCI、AGP、SCSI、DISK....太多,要的话开口。
 
to youngyxy:我要,发给我好吗xjzdy@cnnb.net
 
to nansha
已经发给你了
 
to youngyxy:我也需要这个,发个给我好吗?wwwvw@etang.com 谢谢
 
to edren:
这个控件,专门处理system information的,
你需要开一个贴给分,我发给你
 
获取硬盘ID的函数,直接调用即可。我一直在用。
function GetIdeDiskSerialNumber() : String;
type TSrbIoControl = packed record
HeaderLength : ULONG;
Signature : Array[0..7] of Char;
Timeout : ULONG;
ControlCode : ULONG;
ReturnCode : ULONG;
Length : ULONG;
end;
SRB_IO_CONTROL = TSrbIoControl;
PSrbIoControl = ^TSrbIoControl;

TIDERegs = packed record
bFeaturesReg : Byte; // Used for specifying SMART "commands".
bSectorCountReg : Byte; // IDE sector count register
bSectorNumberReg : Byte; // IDE sector number register
bCylLowReg : Byte; // IDE low order cylinder value
bCylHighReg : Byte; // IDE high order cylinder value
bDriveHeadReg : Byte; // IDE drive/head register
bCommandReg : Byte; // Actual IDE command.
bReserved : Byte; // reserved. Must be zero.
end;

IDEREGS = TIDERegs;
PIDERegs = ^TIDERegs;

TSendCmdInParams = packed record
cBufferSize : DWORD;
irDriveRegs : TIDERegs;
bDriveNumber : Byte;
bReserved : Array[0..2] of Byte;
dwReserved : Array[0..3] of DWORD;
bBuffer : Array[0..0] of Byte;
end;
SENDCMDINPARAMS = TSendCmdInParams;
PSendCmdInParams = ^TSendCmdInParams;

TIdSector = packed record
wGenConfig : Word;
wNumCyls : Word;
wReserved : Word;
wNumHeads : Word;
wBytesPerTrack : Word;
wBytesPerSector : Word;
wSectorsPerTrack : Word;
wVendorUnique : Array[0..2] of Word;
sSerialNumber : Array[0..19] of Char;
wBufferType : Word;
wBufferSize : Word;
wECCSize : Word;
sFirmwareRev : Array[0..7] of Char;
sModelNumber : Array[0..39] of Char;
wMoreVendorUnique : Word;
wDoubleWordIO : Word;
wCapabilities : Word;
wReserved1 : Word;
wPIOTiming : Word;
wDMATiming : Word;
wBS : Word;
wNumCurrentCyls : Word;
wNumCurrentHeads : Word;
wNumCurrentSectorsPerTrack : Word;
ulCurrentSectorCapacity : ULONG;
wMultSectorStuff : Word;
ulTotalAddressableSectors : ULONG;
wSingleWordDMA : Word;
wMultiWordDMA : Word;
bReserved : Array[0..127] of Byte;
end;
PIdSector = ^TIdSector;

const
IDE_ID_FUNCTION = $EC;
IDENTIFY_BUFFER_SIZE = 512;
DFP_RECEIVE_DRIVE_DATA = $0007c088;
IOCTL_SCSI_MINIPORT = $0004d008;
IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501;
DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;
BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize;
W9xBufferSize = IDENTIFY_BUFFER_SIZE+16;
var
hDevice : THandle;
cbBytesReturned : DWORD;
pInData : PSendCmdInParams;
pOutData : Pointer; // PSendCmdOutParams
Buffer : Array[0..BufferSize-1] of Byte;
srbControl : TSrbIoControl absolute Buffer;

procedure ChangeByteOrder( var Data; Size : Integer );
var
ptr : PChar;
i : Integer;
c : Char;
begin
ptr := @Data;
for i := 0 to (Size shr 1)-1 do
begin
c := ptr^;
ptr^ := (ptr+1)^;
(ptr+1)^ := c;
Inc(ptr,2);
end;
end;

begin
Result := '';
FillChar(Buffer,BufferSize,#0);
if Win32Platform=VER_PLATFORM_WIN32_NT then
begin // Windows NT, Windows 2000
// Get SCSI port handle
hDevice := CreateFile( '//./Scsi0:',
GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0 );
if hDevice=INVALID_HANDLE_VALUE then Exit;
try
srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL);
System.Move('SCSIDISK',srbControl.Signature,8);
srbControl.Timeout := 2;
srbControl.Length := DataSize;
srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY;
pInData := PSendCmdInParams(PChar(@Buffer)
+SizeOf(SRB_IO_CONTROL));
pOutData := pInData;
with pInData^ do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegs do
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT,
@Buffer, BufferSize, @Buffer, BufferSize,
cbBytesReturned, nil ) then Exit;
finally
CloseHandle(hDevice);
end;
end
else
begin // Windows 95 OSR2, Windows 98
hDevice := CreateFile( '//./SMARTVSD', 0, 0, nil,
CREATE_NEW, 0, 0 );
if hDevice=INVALID_HANDLE_VALUE then Exit;
try
pInData := PSendCmdInParams(@Buffer);
pOutData := @pInData^.bBuffer;
with pInData^ do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegs do
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA,
pInData, SizeOf(TSendCmdInParams)-1, pOutData,
W9xBufferSize, cbBytesReturned, nil ) then Exit;
finally
CloseHandle(hDevice);
end;
end;
with PIdSector(PChar(pOutData)+16)^ do
begin
ChangeByteOrder(sSerialNumber,SizeOf(sSerialNumber));
SetString(Result,sSerialNumber,SizeOf(sSerialNumber));
end;
end;
 
T0 youngyxy:
那你就干紧发一个给我阿!:lio_cheng@163.com
 
to lio_cheng
事情紧,几天没上DFW。
刚刚发给你。
 
to tianjh007:
  你这段代码在Win2000下怎么什么也读不到了,从代码上看是区分了WinNT/Win9x的,
可是if not DeviceIoControl... 这一行时什么也读不到就退出了!
  你有在WIN2000下试过吗?谢谢!
 
请问各位的代码在SCSI硬盘上做过测试吗?
T0 youngyxy:
谢谢,发一个给我!:conworld@163.com
 
type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;

function GetCPUSpeed: Double;
const
DelayTime = 500;
var
TimerHi,
TimerLo : DWORD;
PriorityClass,
Priority : Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);

SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

Sleep(10);
asm
dw 310Fh
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;

SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);

Result := TimerLo / (1000 * DelayTime);
end;


function GetCPUID: TCPUID; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Resukt}
MOV EAX,1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;

function GetCPUVendor: TVendor; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Result (TVendor)}
MOV EAX,0
DW $A20F {CPUID Command}
MOV EAX,EBX
XCHG EBX,ECX {save ECX result}
MOV ECX,4
@1:
STOSB
SHR EAX,8
LOOP @1
MOV EAX,EDX
MOV ECX,4
@2:
STOSB
SHR EAX,8
LOOP @2
MOV EAX,EBX
MOV ECX,4
@3:
STOSB
SHR EAX,8
LOOP @3
POP EDI {Restore registers}
POP EBX
end;
 
小雨哥,请发一个给我,谢谢
conworld@163.com
 
CPU型號
在注册表中
"HKEY_LOCAL_MACHINE/hardware/DESCRIPTION/System/CentralProcessor/0"
对应VendorIndentifier的值
 
顶部