程式如何實現注冊機制? |
缺席
|
BIG-ROM
初階會員 發表:94 回覆:91 積分:37 註冊:2005-04-16 發送簡訊給我 |
|
pcboy
版主 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
聽不懂, 註冊機制指什麼 ? 您要讀取 Registry 的資訊 ?
提供一個範例: 讀取 Registry (登錄) 中 Service 資訊
// Delphi 7 // 顯示 Registry 中 Service 的狀態 // 請先放上 Memo1 元件, 再貼上本文 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Registry, WinSvc; type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); function GetServiceStatus(service:string): String; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.GetServiceStatus(service:string): String; var service_manager_handle, service_handle:SC_Handle; ss :TServiceStatus; ServiceStatus : String; begin service_manager_handle:=OpenSCManager(Nil,Nil,SC_MANAGER_ALL_ACCESS); service_handle:=OpenService(Service_manager_handle,PChar(service), SERVICE_ALL_ACCESS); if (service_handle > 0) then begin if QueryServiceStatus(service_handle, ss) then begin case ss.dwCurrentState of SERVICE_STOPPED: ServiceStatus:='STOPPED'; // STOPPED 已停用 SERVICE_START_PENDING: ServiceStatus:='START_PENDING'; SERVICE_STOP_PENDING: ServiceStatus:='STOP_PENDING'; SERVICE_CONTINUE_PENDING: ServiceStatus:='CONTINUE_PENDING'; SERVICE_PAUSE_PENDING: ServiceStatus:='PAUSE_PENDING'; SERVICE_RUNNING: ServiceStatus:='RUNNING'; // RUNNING 已啟動 else ServiceStatus:='其它'; end; // case end; // if CloseServiceHandle(service_handle); end; // if CloseServiceHandle(service_manager_handle); Result := ServiceStatus; end; procedure TForm1.FormCreate(Sender: TObject); var i: integer; Registry: TRegistry; RegistryKeyCount : Integer; RootKey : String; Key : String; KeyName : String; DisplayName : String; ImagePath : String; Description : String; ServiceStatus : String; SubKey: TStringList; ValueName: TStringList; begin RootKey := 'HKEY_LOCAL_MACHINE'; Key := '\SYSTEM\CurrentControlSet\Services'; // Memo1.Text:= 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\'; Memo1.Text:= RootKey Key '\'; Memo1.Lines.Add('--------------------------------------------------------------------'); Registry:=TRegistry.Create; Subkey := TStringList.Create; ValueName := TStringList.Create; Registry.RootKey:=HKEY_LOCAL_MACHINE; // Registry.OpenKey('\SYSTEM\CurrentControlSet\Services\', False); Registry.OpenKey(Key '\', False); Registry.GetKeyNames(SubKey); RegistryKeyCount := SubKey.Count-1; for I:=0 to RegistryKeyCount do begin if Registry.OpenKey(Key '\' SubKey[I], False) then begin KeyName := SubKey[i]; Registry.GetValueNames(ValueName); if (KeyName='NDProxy') then DisplayName:='NDIS Proxy' else DisplayName:=Registry.ReadString('DisplayName'); Description := Registry.ReadString('Description'); ImagePath := Registry.ReadString('ImagePath'); ServiceStatus:=GetServiceStatus(KeyName); Memo1.Lines.Add('KeyName: ' KeyName); Memo1.Lines.Add('DisplayName: ' DisplayName); Memo1.Lines.Add('Description: ' Description); Memo1.Lines.Add('ImagePath: ' ImagePath); Memo1.Lines.Add('ServiceStatus: ' ServiceStatus); Memo1.Lines.Add('-----------------------------------------------------'); Registry.CloseKey; end; end; //for I:=0 to Val.Count-1 do SubKey.Clear; ValueName.Clear; Registry.Free; end; end.********************* 如果您滿意答案,請結案 *********************
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案! 子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問! |
BIG-ROM
初階會員 發表:94 回覆:91 積分:37 註冊:2005-04-16 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |