謝建華
本文所有的窗體界面略去,讀者可根據(jù)程序自行添加各窗口組件。 1、獲取windows版本信息 可以通過Windows API函數(shù)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函數(shù)GetSystemInfo來獲得有關(guān)信息。 具體程序如下: procedure TForm1.Button1Click(Sender: TObject); Var SysInfo:SYSTEM_INFO; begin GetSystemInfo(Sysinfo); Edit1.Text:='系統(tǒng)中有'+IntToStr(Sysinfo.dwNumberOfProcessors)+'個CPU' +',類型為'+IntToStr(Sysinfo.dwProcessorType); end;
end.
3、獲取內(nèi)存信息 可以通過Windows API函數(shù)GlobalMemoryStatus來獲得內(nèi)存信息。 具體程序如下: procedure TForm1.Button1Click(Sender: TObject); Var MemInfo:MEMORYSTATUS; begin MemInfo.dwLength:=sizeof(MEMORYSTATUS); GlobalMemoryStatus(MemInfo); memo1.Lines.Add(IntToStr(MemInfo.dwMemoryLoad)+'%的內(nèi)存正在使用') ; memo1.Lines.Add('物理內(nèi)存共有'+IntToStr(MemInfo.dwTotalPhys)+'字節(jié)'); memo1.Lines.Add('可使用的物理內(nèi)存有'+IntToStr(MemInfo.dwAvailPhys)+'字節(jié)'); memo1.Lines.Add('交換文件總大小為'+IntToStr(MemInfo.dwTotalPageFile)+'字節(jié)') ; memo1.Lines.Add('尚可交換文件大小為'+IntToStr(MemInfo.dwAvailPageFile)+'字節(jié)'); memo1.Lines.Add('總虛擬內(nèi)存有'+IntToStr(MemInfo.dwTotalVirtual)+'字節(jié)'); memo1.Lines.Add('未用虛擬內(nèi)存有'+IntToStr(MemInfo.dwAvailVirtual)+'字節(jié)'); end;
end.
或用以下代碼: memo1.Text:=IntToStr(MemInfo.dwMemoryLoad)+'%的內(nèi)存正在使用'+#13#10 +'可使用的物理內(nèi)存有'+IntToStr(MemInfo.dwAvailPhys)+'字節(jié)'+#13#10 +'交換文件總大小為'+IntToStr(MemInfo.dwTotalPageFile)+'字節(jié)'+#13#10 +'尚可交換文件大小為'+IntToStr(MemInfo.dwAvailPageFile)+'字節(jié)'+#13#10 +'總虛擬內(nèi)存有'+IntToStr(MemInfo.dwTotalVirtual)+'字節(jié)'+#13#10 +'未用虛擬內(nèi)存有'+IntToStr(MemInfo.dwAvailVirtual)+'字節(jié)'; 來替代memo1.line.add(…)部分。
4、獲取Windows和系統(tǒng)路徑 可以通過Windows API函數(shù)來獲得 具體程序如下: 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+'; 系統(tǒng)路徑:'+SysDir; end;
end. 其中,筆者通過更改數(shù)列的值:發(fā)現(xiàn)其中的128可更改為人以不小于16的的數(shù)值,若小于或等于16均出現(xiàn)異常(筆者的操作系統(tǒng)為Windows2000)。讀者朋友不妨試試。
5、獲取用戶注冊信息 我們都知道,一般在軟件安裝過程中,它都會提示用戶,要求輸入系列號或產(chǎn)品號和用戶的一些注冊信息(用戶的公司名稱、用戶名等)以及安裝的目錄和路徑等。 通過以下代碼可查看用戶注冊信息: 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:='產(chǎn)品系列號:'+Reg.ReadString('ProductId'); Edit3.Text:='產(chǎn)品名:'+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、關(guān)閉Widows 可以通過Windows API函數(shù)ExitWindowsEx來關(guān)閉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) //安全關(guān)機 else if RadioButton3.Checked=true then ExitWindowsEx(EWX_REBOOT,2) //重新啟動計算機 else if RadioButton4.Checked=true then ExitWindowsEx(EWX_FORCE,4) //強行關(guān)機 else if RadioButton5.Checked=true then ExitWindowsEx(EWX_POWEROFF,8); //關(guān)閉系統(tǒng)并關(guān)閉電源
end;
end.
|