<b>
unit
</b> Main;
<b>
interface
</b>
<b>
uses
</b>
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls, AppEvnts;
<b>
type
</b>
TService1 = <b>
class
</b>(TService)
Timer1: TTimer;
ApplicationEvents1: TApplicationEvents;
<b>
procedure
</b> ServiceAfterInstall(Sender: TService);
<b>
procedure
</b> ServiceStart(Sender: TService; <b>
var
</b> Started:
Boolean
);
<b>
procedure
</b> ServiceStop(Sender: TService; <b>
var
</b> Stopped:
Boolean
);
<b>
procedure
</b> Timer1Timer(Sender: TObject);
<b>
private
</b>
<font color="royalblue"><i>
</i></font>
<b>
public
</b>
<b>
function
</b> GetServiceController: TServiceController; override;
<i><font color="royalblue">
</font></i>
<b>
end
</b>;
<b>
var
</b>
Service1: TService1;
f: TextFile;
Wnd: HWND;
Pos: TPoint;
buff: <b>
array
</b>[<font color="royalblue">
0
</font>..<font color="royalblue">
255
</font>] <b>
of
</b>
char
;
NameClass: <b>
string
</b>;
<b>
implementation
</b>
<i><font color="royalblue">
{$R *.DFM}
</font></i>
<b>
procedure
</b> ServiceController(CtrlCode: DWord); <b>stdcall</b>;
<b>
begin
</b>
Service1
.
Controller( CtrlCode );
<b>
end
</b>;
<b>
function
</b> TService1
.
GetServiceController: TServiceController;
<b>
begin
</b>
Result := ServiceController;
<b>
end
</b>;
<b>
procedure
</b> TService1
.
ServiceAfterInstall(Sender: TService);
<b>
var
</b>
s: <b>
string
</b>;
<b>
begin
</b>
s := ExtractFilePath( Application
.
GetNamePath ) + <font color="royalblue">
'test.txt'
</font>;
AssignFile( f, s );
<b>
if
</b> FileExists( s ) <b>
then
</b>
Append( f )
<b>
else
</b>
Rewrite( f );
<b>
end
</b>;
<b>
procedure
</b> TService1
.
ServiceStart(Sender: TService; <b>
var
</b> Started:
Boolean
);
<b>
begin
</b>
AfterInstall( Sender );
<b>
end
</b>;
<b>
procedure
</b> TService1
.
ServiceStop(Sender: TService; <b>
var
</b> Stopped:
Boolean
);
<b>
begin
</b>
CloseFile( f );
<b>
end
</b>;
<b>
procedure
</b> TService1
.
Timer1Timer(Sender: TObject);
<b>
begin
</b>
GetCursorPos( Pos );
Wnd := WindowFromPoint( Pos );
GetClassName( Wnd, buff, SizeOf( buff ) );
NameClass := StrPas( buff );
Writeln
( f, DateTimeToStr( Now ) + <font color="royalblue">
' '
</font> + ClassName + Format( <font color="royalblue">
' %d %d'
</font>, [Pos
.
x,Pos
.
y] ) );
<b>
end
</b>;
<b>
end
</b>.