幾個擷取Windows系統資訊的Delphi程式

來源:互聯網
上載者:User
本文所有的表單介面略去,讀者可根據程式自行添加各視窗組件。
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) //安全關機
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.