All of the form interfaces in this article are omitted, and readers can add their own widgets according to the program.
1. Get Windows version information
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
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:= ' System has ' +inttostr (sysinfo.dwnumberofprocessors) + ' CPU '
+ ', type ' +inttostr (Sysinfo.dwprocessortype);
End
End.
3. Get Memory information
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 Total ' +inttostr (meminfo.dwtotalphys) + ' bytes ');
Memo1. Lines.add (' Available physical beings ' +inttostr (meminfo.dwavailphys) + ' bytes ');
Memo1. Lines.add (' The total size of the swap file is ' +inttostr (meminfo.dwtotalpagefile) + ' bytes ');
Memo1. Lines.add (' Fair swap file Size ' +inttostr (meminfo.dwavailpagefile) + ' bytes ');
Memo1. Lines.add (' Total virtual within ' +inttostr (meminfo.dwtotalvirtual) + ' bytes ');
Memo1. Lines.add (' Unused virtual beings ' +inttostr (meminfo.dwavailvirtual) + ' bytes ');
End
End.
or use the following code:
Memo1. Text:=inttostr (meminfo.dwmemoryload) + '% of memory is in use ' + #13 # #
+ ' physical beings available ' +inttostr (meminfo.dwavailphys) + ' bytes ' + #13 # #
+ ' The total size of the swap file is ' +inttostr (meminfo.dwtotalpagefile) + ' bytes ' + #13 # #
+ ' Fair swap file Size ' +inttostr (meminfo.dwavailpagefile) + ' bytes ' + #13 # #
+ ' total virtual within ' +inttostr (meminfo.dwtotalvirtual) + ' bytes ' + #13 # #
+ ' unused virtual beings ' +inttostr (meminfo.dwavailvirtual) + ' bytes ';
To replace Memo1.line.add (...) Part.
4. Get Windows and System paths
You can use Windows API functions to get
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 by changing the value of the series: found that 128 can be changed to a person with a value of not less than 16, if less than or equal to 16 is an exception (the author's operating system is Windows2000). Readers may wish to try.
5. Get User registration Information
As we all know, generally during the software installation process, it prompts the user to enter the serial number or product number and some of the user's registration information (the user's company name, user name, etc.), as well as the installed directory and path.
Use the following code to view user registration information:
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: You must add the registry cell under the uses statement before the program compiles.
6. Close Widows
You can turn widows off by using the Windows API function ExitWindowsEx.
Procedure Tform1.button1click (Sender:tobject);
Begin
If Radiobutton1.checked=true Then
ExitWindowsEx (ewx_logoff,0)//log in as a different user
else if Radiobutton2.checked=true then
ExitWindowsEx (ewx_shutdown,1)//safety shutdown
else if Radiobutton3.checked=true then
ExitWindowsEx (ewx_reboot,2)//Restart the computer
else if Radiobutton4.checked=true then
ExitWindowsEx (ewx_force,4)//forced shutdown
else if Radiobutton5.checked=true then
ExitWindowsEx (ewx_poweroff,8); Turn off the system and turn off the power
End
End.
This article was reproduced from: http://tech.ccidnet.com/art/1079/20060407/500873_1.html
http://blog.csdn.net/akof1314/article/details/6191051
Several Delphi programs to get Windows System Information