Skip to content

Commit fcb207f

Browse files
committed
[services] some compatibility changes
1 parent 849b22c commit fcb207f

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

Quick.Service.pas

+62-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ interface
3434

3535
uses
3636
SysUtils,
37+
{$IFDEF MSWINDOWS}
3738
Windows,
38-
{$IFNDEF FPC}
3939
Messages,
4040
WinSvc,
41+
{$ENDIF}
42+
{$IFNDEF FPC}
4143
System.IOUtils,
4244
{$ELSE}
4345
Quick.Files,
4446
{$ENDIF}
4547
Quick.Commons,
4648
Quick.Process;
4749

50+
{$IFDEF MSWINDOWS}
4851
type
4952
TServiceState = (ssUnknow = -1,
5053
ssStopped = SERVICE_STOPPED,
@@ -54,17 +57,63 @@ interface
5457
ssContinuePending = SERVICE_CONTINUE_PENDING,
5558
ssPausePending = SERVICE_PAUSE_PENDING,
5659
ssPaused = SERVICE_PAUSED);
60+
{$ENDIF}
5761

58-
function ServiceIsPresent(const aMachine, aServiceName : string): Boolean;
62+
{$IFDEF MSWINDOWS}
63+
function ServiceIsPresent(const aServiceName : string): Boolean; overload;
64+
function ServiceIsPresent(const aMachine, aServiceName : string): Boolean; overload;
5965
function GetServicePath : string;
6066
function GetServiceState(const aServer, aServiceName : string) : TServiceState;
61-
function ServiceStart(const aMachine, aServiceName : string) : Boolean;
62-
function ServiceStop(const aMachine, aServiceName : string ) : Boolean;
67+
function ServiceStart(const aServiceName : string) : Boolean; overload;
68+
function ServiceStop(const aServiceName : string ) : Boolean; overload;
69+
function ServiceStart(const aMachine, aServiceName : string) : Boolean; overload;
70+
function ServiceStop(const aMachine, aServiceName : string ) : Boolean; overload;
71+
{$ELSE}
72+
function ServiceIsPresent(const aServiceName : string): Boolean;
73+
function ServiceStart(const aServiceName : string) : Boolean;
74+
function ServiceStop(const aServiceName : string ) : Boolean;
75+
{$ENDIF}
6376
function ServiceUninstall(const aServiceName : string): Boolean;
77+
{$IFDEF MSWINDOWS}
6478
function DeleteServiceEx(svcName : string) : Boolean;
79+
{$ENDIF}
6580

6681
implementation
6782

83+
function ServiceIsPresent(const aServiceName : string) : Boolean;
84+
{$IFDEF MSWINDOWS}
85+
begin
86+
Result := ServiceIsPresent('localhost',aServiceName);
87+
end;
88+
{$ELSE}
89+
begin
90+
91+
end;
92+
{$ENDIF}
93+
94+
function ServiceStart(const aServiceName : string) : Boolean;
95+
{$IFDEF MSWINDOWS}
96+
begin
97+
Result := ServiceStart('localhost',aServiceName);
98+
end;
99+
{$ELSE}
100+
begin
101+
102+
end;
103+
{$ENDIF}
104+
105+
function ServiceStop(const aServiceName : string) : Boolean;
106+
{$IFDEF MSWINDOWS}
107+
begin
108+
Result := ServiceStop('localhost',aServiceName);
109+
end;
110+
{$ELSE}
111+
begin
112+
113+
end;
114+
{$ENDIF}
115+
116+
{$IFDEF MSWINDOWS}
68117
function ServiceIsPresent(const aMachine, aServiceName : string): Boolean;
69118
var
70119
smanHnd : SC_Handle;
@@ -202,8 +251,10 @@ function ServiceStop(const aMachine, aServiceName : string ) : Boolean;
202251
end;
203252
Result := SERVICE_STOPPED = svcStatus.dwCurrentState;
204253
end;
254+
{$ENDIF}
205255

206256
function ServiceUninstall(const aServiceName : string): Boolean;
257+
{$IFDEF MSWINDOWS}
207258
var
208259
smanHnd : SC_Handle;
209260
svchnd : SC_Handle;
@@ -236,7 +287,13 @@ function ServiceUninstall(const aServiceName : string): Boolean;
236287
end;
237288
end;
238289
end;
290+
{$ELSE}
291+
begin
292+
293+
end;
294+
{$ENDIF}
239295

296+
{$IFDEF MSWINDOWS}
240297
function DeleteServiceEx(svcName : string) : Boolean;
241298
begin
242299
Result := False;
@@ -245,5 +302,6 @@ function DeleteServiceEx(svcName : string) : Boolean;
245302
Result := ShellExecuteAndWait('open','sc','delete '+svcName,'',0,True) = 0;
246303
end;
247304
end;
305+
{$ENDIF}
248306

249307
end.

0 commit comments

Comments
 (0)