Several Delphi programs for obtaining Windows system information

All the window interfaces in this article are omitted, and readers can add various window components according to the program.
1. Get the windows version information
It can be obtained through the Windows API function GetVersionEx.
The specific procedures are as follows:
Procedure Tform1.Button1Click(sender:TObject);
Var
OSVI:OSVERSIONINFO;
begin
OSVI.dwOSversioninfoSize:=Sizeof(OSVERSIONINFO);
GetVersionEx(OSVI);
label1.Caption:=IntToStr(OSVI.dwMinorVersion)+ ‘,’
+IntToStr(OSVI.dwMinorVersion)+ ‘,’
+IntToStr(OSVI.dwBuildNumber)+ ‘,’
+IntToStr(OSVI.dwPlatformId)+ ‘,’
+OSVI.szCSDVersion;
end;
end.
2. Get CPU information
Relevant information can be obtained through the Windows API function GetSystemInfo.
The specific procedures are as follows:
procedure TForm1.Button1Click(Sender: TObject);
Var
SysInfo:SYSTEM_INFO;
begin
GetSystemInfo(Sysinfo);
Edit1.Text:= ‘In the system’+IntToStr(Sysinfo.dwNumberOfProcessors)+ ‘CPU’
+ ‘,Type is’+IntToStr(Sysinfo.dwProcessorType);
end;
end.
3. Get memory information
The memory information can be obtained through the Windows API function GlobalMemoryStatus.
The specific procedures are as follows:
procedure TForm1.Button1Click(Sender: TObject);
Var
MemInfo:MEMORYSTATUS;
begin
MemInfo.dwLength:=sizeof(MEMORYSTATUS);
GlobalMemoryStatus(MemInfo);
memo1.Lines.Add(IntToStr(MemInfo.dwMemoryLoad)+ ‘%Of memory is in use’) ;
memo1.Lines.Add( ‘Physical memory shared’+IntToStr(MemInfo.dwTotalPhys)+ ‘byte’);
memo1.Lines.Add( ‘Available physical memory is’+IntToStr(MemInfo.dwAvailPhys)+ ‘byte’);
memo1.Lines.Add( ‘The total size of the swap file is’+IntToStr(MemInfo.dwTotalPageFile)+ ‘byte’) ;
memo1.Lines.Add( ‘The remaining swap file size is’+IntToStr(MemInfo.dwAvailPageFile)+ ‘byte’);
memo1.Lines.Add( ‘Total virtual memory has’+IntToStr(MemInfo.dwTotalVirtual)+ ‘byte’);
memo1.Lines.Add( ‘Unused virtual memory’+IntToStr(MemInfo.dwAvailVirtual)+ ‘byte’);
end;
end.
Or use the following code:
Memo1.Text:=IntToStr(MemInfo.dwMemoryLoad)+ ‘%Of memory is in use’+# 13# 10
+ ‘Available physical memory is’+IntToStr(MemInfo.dwAvailPhys)+ ‘byte’+# 13# 10
+ ‘The total size of the swap file is’+IntToStr(MemInfo.dwTotalPageFile)+ ‘byte’+# 13# 10
+ ‘The exchangeable file size is’+IntToStr(MemInfo.dwAvailPageFile)+ ‘byte’+# 13# 10
+ ‘Total virtual memory has’+IntToStr(MemInfo.dwTotalVirtual)+ ‘byte’+# 13# 10
+ ‘Unused virtual memory’+IntToStr(MemInfo.dwAvailVirtual)+ ‘byte’;
To replace the memo1.line.add(…) part.
4. Get Windows and system path
Can be obtained through Windows API functions
The specific procedures are as follows:
procedure TForm1.Button1Click(Sender: TObject);
Var
SysDir:array [0..128] of char;
begin
GetWindowsDirectory(SysDir, 128);
Edit1.Text:= ‘Windows path:’+SysDir;
GetSystemDirectory(SysDir, 128);
Edit1.Text:=Edit1.Text+ ‘; System path:’+SysDir;
end;
end.
Among them, the author changed the value of the series: I found that 128 can be changed to a value not less than 16, if it is less than or equal to 16, abnormalities occur (the author’s operating system is Windows2000). Readers may wish to try.
5. Obtain user registration information
As we all know, generally during the software installation process, it will prompt the user to enter the serial number or product number and some user registration information (user’s company name, user name, etc.), as well as the installation directory and path.
The user registration information can be viewed through the following code:
procedure TForm1.Button1Click(Sender: TObject);
Var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey( ‘Software/Microsoft/Windows NT/CurrentVersion’,False);
Edit1.Text:= ‘Current path:’+Reg.CurrentPath;
Edit2.Text:= ‘Product serial number:’+Reg.ReadString( ‘ProductId’);
Edit3.Text:= ‘product name:’+Reg.ReadString( ‘ProductName’);
Edit4.Text:= ‘Registered company name:’+Reg.ReadString( ‘RegisteredOrganization’);
Edit5.Text:= ‘username:’+Reg.ReadString( ‘RegisteredOwner’);
Edit6.Text:= ‘Software type:’+Reg.ReadString( ‘SoftwareType’);
Reg.CloseKey;
Reg.Free;
end;
end.
Note: Before the program is compiled, the registry unit must be added under the USES statement.
6. Close Widows
Widows can be closed through the Windows API function ExitWindowsEx.
procedure TForm1.Button1Click(Sender: TObject);
begin
if RadioButton1.Checked=true then
ExitWindowsEx(EWX_LOGOFF, 0) //Log in as another user
else if RadioButton2.Checked=true then
ExitWindowsEx(EWX_SHUTDOWN, 1) //Safe shutdown
else if RadioButton3.Checked=true then
ExitWindowsEx(EWX_REBOOT, 2) //重Newly booted computer
else if RadioButton4.Checked=true then
ExitWindowsEx(EWX_FORCE, 4) //Forced shutdown
else if RadioButton5.Checked=true then
ExitWindowsEx(EWX_POWEROFF, 8); //Shut down the system and power off
end;
end.