• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

delphi 搞代码 7年前 (2018-08-09) 166次浏览 已收录 0个评论

谢建华

本文所有的窗体界面略去,读者可根据程序自行添加各窗口组件。
1、获取windows版本信息
可以通过Windows API函数GetVersionEx来获得。
具体程序如下:
Procedure Tform1.Button1Click(sender:TObject);
Var
OSVI:OSVERSIONINFO;
begin

http://www.gaodaima.com/?p=65827几个获取Windows系统信息的Delphi程序_Delphi

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.

欢迎大家阅读《几个获取Windows系统信息的Delphi程序_Delphi》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:几个获取Windows系统信息的Delphi程序_Delphi

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址