Get system information with Windows API functions and registry

xiaoxiao2021-03-06  62

Get system information with Windows API functions and registry

Author: Evaluation: the station Date: 2004-04-18 Description: Source:

When developing an application, add a function of displaying computer system information, such as installed floppy disk, hard disk, optical drive, network drive, hard disk capacity, and remaining space, display resolution, keyboard type, mouse button, memory size , CPU type, Windows version number, product ID, registered user unit name, and username, current operation user name, etc. (see running graphic), of course, there is more information, which will make your program more friendly. In fact, there are many applications to do this. You can get a lot of system information by calling Windows API functions and accessing a Windows registry. Delphi provides call interfaces for most WindowsAPI functions (see Delphi3 / Source / RTL / Win / Windows.Pas file), and provides a full-featured Tregistry class so that we can easily call WindowsAPI functions and access registry. , For example: 1, function getDriveType (lprootpathname: pchar): uint; return to the type of driven device. 2, function GetDiskFreeSpace (lpRootPathName: PChar; var lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters: DWORD): BOOL; return refers to the total number of clusters given drive, the remaining number of clusters and the number of sectors per cluster, per sector Word The number of hours can be calculated to calculate the total capacity and remaining spaces. 3, Function GetSystemMetrics (SM_CXSCREEN or SM_CYSCREEN): Integer; Return the display of the display. 4, Function GetSystemMetrics: Integer; Number of keys returns to the mouse. 5. The HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Registered / Windows / CurrentVersion / Registered / Windows / CurrentVersion / Registered / Windows / CurrentVersion / Registered / Windows / CurrentVersion / Registered / Windows / CurrentVersion / Registered, which can be read in the following statement. myreg: = Tregistry.Create; file: // Registrymyreg.RootKey must be added in the uses of the program unit: = HKEY_LOCAL_MACHINE; if myreg.openkey (Note: software / microsoft / windows / currentversion Notes:, false) then memo1.lines. Add (Note: Registered User Name: Note: MyReg.Readstring (Note: Registered "); myreg.closekey; only a few cases, the method of obtaining his information is similar, See the source program. The program is called at PWIN95 and Delphi3. Attachment: Source Principle.

unit Unit1; interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Registry; typeTForm1 = class (TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click (Sender: TObject); private {Private declarations } public {public declarations} End; varform1: tform1; importation {$ r * .dfm} Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR i, x, y: integer; ch: char; file: // Drive Character Comment : A Note: ~ Note: z Comment: Buffer: string; cpuinfo: TsystemInfo; file: // Store system information record type, check the details in Windows.Pas. MEMINFO: TMEMORYSTATUS; file: // Stores the record type of system memory information.

Computername, UserName: Pchar; File: // Computer Name, Username SPC, BPS, NOFC, Tnoc: longint; file: // MYREG: Tregistry; file: // is used to access the registry TregiSTR variable BeginMemo1.Lines.clear; for ch: = Note: a Note: To Note: DO Begini: = GetDriveType (Pchar (CH Note :: / Comment :)); buffer: = Note: Note: CH Note :: Note:; case i ofDRIVE_UNKNOWN: buffer: = buffer NOTE: unknown type comment:; DRIVE_REMOVABLE: buffer: = buffer NOTE: floppy Note:; DRIVE_FIXED: beginbuffer: = buffer NOTE: hard Note:; if getdiskfreespace (pchar ( CH Note :: / Note :), SPC, BPS, NOFC, TNOC) THEN BEGINBUFFER: = Buffer Note: Total Capacity: Note: INTTOSTR ((SPC * BPS * Tnoc) DIV (1024 * 1024)) Note: MB Note:; Buffer: = BUFFER Note: Remain: Note: INTTOSTR (SPC * BPS * NOFC) DIV (1024 * 1024)) Note: MB Note:; End; End; Drive_remote: Buffer: = Buffer Note: Network Drive Note: = BUFFER Note: CD-ROM Drive Note:; Drive_ramdisk: Buffer: = Buffer Note: RAM Virtual Drive Note:; END; if (ch> Note: D Note :) And (i = 1 ); If i <> 1 damo1.lines.add (buffer); end; case getKeyboardType (0) of file: // Get keyboard type 1: buffer: = Note: Keyboard: IBM PC / XT or compatible type (83 key) Note: 2: buffer: = Note: Keyboard: Olivetti "ICO" (102 key) Note:; 3: Buffer: = Note: Keyboard: IBM PC / AT (84 key) Note:; 4: Buffer: = Note: Keyboard: IBM Enhanced (101 or 102 Key) Note:; 5: Buffer: = Note: Keyboard: Nokia 1050 Note:; 6: Buffer: = Note: Keyboard: Nokia 9140 Note:; 7: BUFFER : = Note: Keyboard: Japanese Note:; End; memo1.lines.add (buffer); file: // Get keyboard function keys MEMO1.LINES.ADD (Note: Function: Number of function: Note: INTOARDTYPE (2 ))))

Memo1.Lines.Add (Note: Display Resolution: Note: INTTOSTR (SM_CXSCREEN)) Note: x Note: INTSTR (GetSystemMetr ")); file: // Gets the number of mouse buttons MEMO1.LINES. Add (Note: Mouse: Note: INTTOSTR (SM_CMouseButtons) Note: Key Inspiration :); GlobalMemoryStatus (MemInfo); File: // Get System Memory Number Memo1.Lines.Add (Note: Physical Memory: Note: INTTOSTR (MemInfo.dwtotalphys Div 1024) Note: KB Note :); i: = getSystemMetrics (SM_CLEANBOOT); Case I of0: Buffer: = Note: System Launch Mode: Normal Mode Note: 1: Buffer: = Note: System launch mode: Protection mode Note:; 2: Buffer: = Note: System launch mode: Network protection mode Note:; end; memo1.lines.add (buffer); x: = getSystemMetrics (SM_ARRANGE); file: // Get System Minimize Window Start Location and Arrange Y: = x; x: = x And 3; Y: = Y AND 12; Case X Ofarw_bottomleft: Buffer: = Note: Minimize Window: From The lower left corner:; ARW_BOTTOMRIGHT : Buffer: = Note: Minimize window: In the lower right corner:; arw_topleft: buffer: = Note: Minimize window: From the upper corner:; arw_topright: buffer: = Note: Minimize window: From the upper right corner:; END; CASE Y Oft: Buffer: = Buffer Note: Transverse Arrange Note:; ARW_UP: Buffer: = Buffer Note: Longitudinal Arrange Note:; ARW_HIDE: BUFFER: = Buffer Note: Hidden Note:; End; Memo1.Lines.Add ( Buffer; getMem (ComputerName, 255); file: // Get computer name and username getMem (username, 255); i: = 255; getcomputername (c OMPUTERNAME, I); MEMO1.LINES.ADD (Note: Computer Name: Note: ComputerName); getUserName (username, i); memo1.lines.add (Name: Name: Name: Name: username); Freemem (ComputerName) Freemem (UserName); getSystemInfo (CPUINFO); File: // Get CPU Type Case cpuinfo.dwprocessortype of386: Buffer: = Note: CPU Type: 386 Note:; 486: Buffer: = Note: CPU Type: 486 Note:; 586: Buffer: = Note: CPU Type: Pentium Note:;

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

New Post(0)