レジストリ監視(Delphi)

レジストリ監視(Delphi)

使い方

procedure RegistryMonitor(RootKey: HKEY; Key: string; Proc: TProc; WatchSub: boolean);
begin
	TThread.CreateAnonymousThread(procedure
	var
		Reg: TRegistry;
		Event: cardinal;
	begin
		Reg := TRegistry.Create;
		Reg.RootKey := RootKey;
		if Reg.OpenKeyReadOnly(Key) then
		begin
			Event := CreateEvent(nil, False, False, nil);
			if Event > 0 then
			begin
				while True do
				begin
					RegNotifyChangeKeyValue(Reg.CurrentKey, WatchSub, REG_NOTIFY_CHANGE_LAST_SET, Event, True);
					if WaitForSingleObject(Event, INFINITE) = WAIT_OBJECT_0 then TThread.Synchronize(TThread.CurrentThread, procedure begin Proc end);
				end;
			end;
		end;
	
		Reg.Free;
	end).Start;
end;

// proc:コマンドを入力します

// WatchSub:部下を監視しますか?

RegistryMonitor(RootKey, Key, Proc, WatchSub);

Leave a Reply

이메일 주소는 공개되지 않습니다. (* 질문, 건의사항 등은 "질문게시판"을 이용해주세요)