Use Delphi to get system information

zhaozj2021-02-17  97

l Get a series of information using Delphi

Delphi is increasingly favored by programming enthusiasts with its excellent visual programming, flexible Windows API interface.

In Delphi, by calling the Windows API, it is convenient to get system information, which helps us write better Windows applications. The following procedures are compiled under Delphi3.0 for Windows 9X.

First, get disk information with getDriveType function

LBL_DRIVETYPE: TLABEL;

DriveType: word; // Defines the drive type variable

DriveType: = getDriveType (rootpathname); // Get the disk drive information corresponding to rootpathname

Case DriveType of

DRIVE_REMOVABLE: LBL_DRIVETYPE.CAPTION: = 'Floppy Drive'

DRIVE_FIXED: LBL_DRIVETYPE.CAPTION: = 'Hard Drive';

DRIVE_REMOTE: LBL_DRIVETYPE.CAPTION: = 'Network Drive';

DRIVE_CDROM: LBL_DRIVETYPE.CAPTION: = 'CD Drive';

Drive_ramdisk: lbl_drivetype.caption: = 'memory virtual disc';

End; // Display the disk information in LBL_DRIVETYPE

Second, get memory usage information with the globalmemorystatus function

MemStatus: tmemorystatus; // Define memory structure variables

LBL_MEMORY: TLABEL;

MemStatus.dwlength: = size of (tmemorystatu

S);

GlobalMemoryStatus (Memstatus); // Return to memory usage information

LBL_MEMORY.CAPTION: = Format ('total memory:% D KB available memory:% DKB', [MemStatus.dwavailphys Div 1024, Memstatus.dwtotalphys Div 1024]);

// Display memory information in LBL_MEMORY

Third, get the CPU information with getSysteminfo function

Sysinfo: tsysteminfo;

LBL_CPUNAME: TLABEL;

GetSystemInfo (sysinfo); // Get CPU information

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; // Display the CPU information in LBL_CPuname.

转载请注明原文地址:https://www.9cbs.com/read-31407.html

New Post(0)