几个获取Windows系统信息的Delphi程序

本文介绍如何利用Delphi编程语言来获取Windows操作系统的详细信息,包括版本、硬件配置等,帮助开发者实现系统级别的诊断和监控功能。
1、获取Windows版本信息 

可以通过Windows API函数GetVersionEx来获得。 

具体程序如下: 

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、获取CPU信息 

可以通过Windows API函数GetSystemInfo来获得有关信息。 

具体程序如下: 

procedure TForm1.Button1Click(Sender: TObject); 
Var 
SysInfo:SYSTEM_INFO; 
begin 
GetSystemInfo(Sysinfo); 
Edit1.Text:='系统中有'+IntToStr(Sysinfo.dwNumberOfProcessors)+'个CPU' 
+',类型为'+IntToStr(Sysinfo.dwProcessorType); 
end; 

end.
 


3、获取内存信息 

可以通过Windows API函数GlobalMemoryStatus来获得内存信息。 

具体程序如下: 

procedure TForm1.Button1Click(Sender: TObject); 
Var 
MemInfo:MEMORYSTATUS; 
begin 
MemInfo.dwLength:=sizeof(MEMORYSTATUS); 
GlobalMemoryStatus(MemInfo); 
memo1.Lines.Add(IntToStr(MemInfo.dwMemoryLoad)+'%的内存正在使用') ; 
memo1.Lines.Add('物理内存共有'+IntToStr(MemInfo.dwTotalPhys)+'字节'); 
memo1.Lines.Add('可使用的物理内存有'+IntToStr(MemInfo.dwAvailPhys)+'字节'); 
memo1.Lines.Add('交换文件总大小为'+IntToStr(MemInfo.dwTotalPageFile)+'字节') ; 
memo1.Lines.Add('尚可交换文件大小为'+IntToStr(MemInfo.dwAvailPageFile)+'字节'); 
memo1.Lines.Add('总虚拟内存有'+IntToStr(MemInfo.dwTotalVirtual)+'字节'); 
memo1.Lines.Add('未用虚拟内存有'+IntToStr(MemInfo.dwAvailVirtual)+'字节'); 
end; 

end.
 


或用以下代码: 

memo1.Text:=IntToStr(MemInfo.dwMemoryLoad)+'%的内存正在使用'+#13#10 
+'可使用的物理内存有'+IntToStr(MemInfo.dwAvailPhys)+'字节'+#13#10 
+'交换文件总大小为'+IntToStr(MemInfo.dwTotalPageFile)+'字节'+#13#10 
+'尚可交换文件大小为'+IntToStr(MemInfo.dwAvailPageFile)+'字节'+#13#10 
+'总虚拟内存有'+IntToStr(MemInfo.dwTotalVirtual)+'字节'+#13#10 
+'未用虚拟内存有'+IntToStr(MemInfo.dwAvailVirtual)+'字节';
 


来替代memo1.line.add(…)部分。 

4、获取Windows和系统路径 

可以通过Windows API函数来获得 

具体程序如下: 

procedure TForm1.Button1Click(Sender: TObject); 
Var 
SysDir:array[0..128] of char; 
begin 
GetWindowsDirectory(SysDir,128); 
Edit1.Text:='Windows 路径:'+SysDir; 
GetSystemDirectory(SysDir,128); 
Edit1.Text:=Edit1.Text+'; 系统路径:'+SysDir; 
end; 

end.
 


其中,笔者通过更改数列的值:发现其中的128可更改为人以不小于16的的数值,若小于或等于16均出现异常(笔者的操作系统为Windows2000)。读者朋友不妨试试。 

5、获取用户注册信息 

我们都知道,一般在软件安装过程中,它都会提示用户,要求输入系列号或产品号和用户的一些注册信息(用户的公司名称、用户名等)以及安装的目录和路径等。 

通过以下代码可查看用户注册信息: 

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:='当前路径:'+Reg.CurrentPath; 
Edit2.Text:='产品系列号:'+Reg.ReadString('ProductId'); 
Edit3.Text:='产品名:'+Reg.ReadString('ProductName'); 
Edit4.Text:='注册公司名称:'+Reg.ReadString('RegisteredOrganization'); 
Edit5.Text:='用户名:'+Reg.ReadString('RegisteredOwner'); 
Edit6.Text:='软件类型:'+Reg.ReadString('SoftwareType'); 
Reg.CloseKey; 
Reg.Free; 
end; 

end.
 


注意:在程序编译之前,必须在USES语句下添加registry单元。 

6、关闭Widows 

可以通过Windows API函数ExitWindowsEx来关闭Widows。 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
if RadioButton1.Checked=true then 
ExitWindowsEx(EWX_LOGOFF,0) //以其他用户身份登录 
else if RadioButton2.Checked=true then 
ExitWindowsEx(EWX_SHUTDOWN,1) //安全关机 
else if RadioButton3.Checked=true then 
ExitWindowsEx(EWX_REBOOT,2) //重新启动计算机 
else if RadioButton4.Checked=true then 
ExitWindowsEx(EWX_FORCE,4) //强行关机 
else if RadioButton5.Checked=true then 
ExitWindowsEx(EWX_POWEROFF,8); //关闭系统并关闭电源 

end; 

end.

 
Delphi获取Windows版本号、描述等信息,可获取到主版本号、次版本号、系统描述、系统平台、构建号等,相关代码如下:   //设置版本信息结构的大小    GetVersionEx(OSVI);    //获取版本信息    is98orlater:=    //判断是否98或以后版本    (osvi.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS) and    ((osvi.dwMajorVersion>4) or    ((osvi.dwMajorVersion=4) and (osvi.dwMinorVersion>0)));   //DOWNLOAD BY HTTP://WWW.CODEFANS.NET    //下面开始显示信息    case OSVI.dwPlatformId of    //根据OSVI.dwPlatformId的数值的不同显示具体的平台描述    VER_PLATFORM_WIN32s:    // Windows 3.1平台    s:='Windows 3.1';    VER_PLATFORM_WIN32_WINDOWS:    // Windows 95/98平台    if(is98orlater) then    //98    s:='Windows 98'    else    //95    s:='Windows 95';    VER_PLATFORM_WIN32_NT:    // Windows NT平台    s:='Windows NT/XP';    end;    Edit1.Text:=s;    Edit2.Text:=IntToStr(OSVI.dwMajorVersion);    Edit3.Text:=IntToStr(OSVI.dwMinorVersion);    case OSVI.dwPlatformId of    //根据平台的不同具体处理OSVI.dwBuildNumber信息    VER_PLATFORM_WIN32_WINDOWS:    // Windows 95/98平台则取OSVI.dwBuildNumber的低位字    Edit4.Text:=IntToStr(LOWORD(OSVI.dwBuildNumber));    VER_PLATFORM_WIN32_NT:    // Windows NT平台则取所有位的值    Edit4.Text:=IntToStr(OSVI.dwBuildNumber);    else    Edit4.Text:='';   // Windows 3.1平台此值位空    end;    Edit5.Text:=OSVI.szCSDVersion;   end;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值