几个获取Windows系统信息的Delphi程序 所有的窗体界面略去,可根据程序自行添加各窗口组件(均为常规组件,属性默认)。 1、获取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; 2、获取内存信息 可以通过Windows API函数GlobalMemoryStatus来获得内存信息。 具体程序如下: procedure TForm1.Button2Click(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; 3、获取Windows和系统路径 可以通过Windows API函数来获得 具体程序如下: procedure TForm1.Button3Click(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; 4、关闭Widows 可以通过Windows API函数ExitWindowsEx来关闭Widows。 procedure TForm1.Button4Click(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;
|