unit Capture_main;<br>interfaceuses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs,ExtCtrls, StdCtrls,registry,WinProcs;<br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure WMQueryEndSession (var Message: TMessage);<br> message WM_QUERYENDSESSION ;<br> end;<br>var<br> Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>procedure TForm1.FormCreate(Sender: TObject);<br>var Reg: Tregistry;<br>begin<br> RegisterServiceProcess( GetCurrentProcessID, 1 );<br> Reg := Tregistry.Create ;<br> Reg.RootKey := HKEY_LOCAL_MACHINE;<br> if not reg.KeyExists('SOFTWARE/monitor')<br> then begin<br> Reg.CreateKey ('SOFTWARE/monitor');<br> Reg.Writestring('AutoRun', 'true');<br> Reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true);<br> Reg.WriteString('monitor_server',application.ExeName );<br> end;<br> Reg.CloseKey;<br> Reg.Free;<br> end;<br>procedure TForm1.WMQueryEndSession (var Message: TMessage);<br>var<br> Reg: Tregistry;<br>begin<br> Reg := Tregistry.Create ;<br> Reg.RootKey := HKEY_LOCAL_MACHINE;<br> Reg.OpenKey ('SOFTWARE/monitor',true);<br> if Reg.ReadString('AutoRun') = 'true' then<br> begin<br> Reg.CloseKey;<br> Reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run', true);<br> Reg.WriteString('monitor_server',application.ExeName );<br> Reg.CloseKey;<br> Reg.Free;<br> end;<br> Form1.Close;<br>end;<br>end.