-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSvc95Main.pas
68 lines (56 loc) · 1.23 KB
/
Svc95Main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
unit Svc95Main;
interface
procedure ServiceMain;
implementation
uses Windows, Messages, SysUtils, ActiveX, ComObj, ComServ, ConfigObj,
NetTimeCommon, NetTimeThread, winerr, WinSvc;
const
RPC_C_AUTHN_LEVEL_NONE = 1;
RPC_C_IMP_LEVEL_IMPERSONATE = 3;
EOAC_NONE = 0;
var
DoneExit: boolean;
type
TSetDoneObj = class
class procedure DoExitNow(Sender: TObject);
end;
class procedure TSetDoneObj.DoExitNow(Sender: TObject);
begin
DoneExit := true;
end;
procedure ServiceMain;
var
co: TConfigObj;
tt: TNetTimeServer;
Msg: TMsg;
result: LongBool;
begin
tt := TNetTimeServer.Create;
co := TConfigObj.Create;
try
co.ReadFromRegistry;
co.WriteToRunning(tt);
finally
co.Free;
end;
if (tt.Config.ServerCount = 0) then
raise exception.create('NetTime has not been configured');
tt.OnExitNow := TSetDoneObj.DoExitNow;
tt.Start;
DoneExit := false;
repeat
result := PeekMessage(Msg, 0, 0, 0, PM_REMOVE);
if result then
begin
if (Msg.Message = WM_QUIT) or (Msg.Message = WM_ENDSESSION) then
DoneExit := true;
TranslateMessage(Msg);
DispatchMessage(Msg);
end
else
Sleep(GUISleepTime);
until DoneExit;
tt.Stop;
CoUninitialize;
end;
end.