Skip to content

Commit 9c50a6e

Browse files
authored
Merge pull request #124 from corneliusdavid/master
add service description; grammar correction
2 parents 4c35b68 + ea8893c commit 9c50a6e

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

Quick.AppService.pas

+35-3
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,18 @@ TAppService = class
9696
fOnStop : TSvcAnonMethod;
9797
fOnExecute : TSvcAnonMethod;
9898
fAfterRemove : TSvcRemoveEvent;
99+
fServiceDescription : string;
99100
procedure ReportSvcStatus(dwCurrentState, dwWin32ExitCode, dwWaitHint: DWORD);
100101
procedure Execute;
101102
procedure Help;
102103
procedure DoStop;
104+
procedure SetServiceDescription;
103105
public
104106
constructor Create;
105107
destructor Destroy; override;
106108
property ServiceName : string read fServiceName write fServiceName;
107109
property DisplayName : string read fDisplayName write fDisplayName;
110+
property ServiceDescription : string read fServiceDescription write fServiceDescription;
108111
property LoadOrderGroup : string read fLoadOrderGroup write fLoadOrderGroup;
109112
property Dependencies : string read fDependencies write fDependencies;
110113
property DesktopInteraction : Boolean read fDesktopInteraction write fDesktopInteraction;
@@ -138,6 +141,11 @@ TAppService = class
138141

139142
implementation
140143

144+
{$IFDEF MSWINDOWS}
145+
uses
146+
Registry;
147+
{$ENDIF}
148+
141149
procedure ServiceCtrlHandler(Control: DWORD); stdcall;
142150
begin
143151
case Control of
@@ -242,6 +250,27 @@ procedure TAppService.ReportSvcStatus(dwCurrentState, dwWin32ExitCode, dwWaitHin
242250
SetServiceStatus(StatusHandle,ServiceStatus);
243251
end;
244252

253+
procedure TAppService.SetServiceDescription;
254+
{$IFDEF MSWINDOWS}
255+
var
256+
reg: TRegistry;
257+
{$ENDIF}
258+
begin
259+
{$IFDEF MSWINDOWS}
260+
reg := TRegistry.Create(KEY_READ or KEY_WRITE);
261+
try
262+
reg.RootKey := HKEY_LOCAL_MACHINE;
263+
if reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + fServiceName, False) then
264+
begin
265+
reg.WriteString('Description', fServiceDescription);
266+
reg.CloseKey;
267+
end;
268+
finally
269+
reg.Free;
270+
end;
271+
{$ENDIF}
272+
end;
273+
245274
procedure TAppService.Execute;
246275
begin
247276
//we have to do something or service will stop
@@ -320,7 +349,7 @@ procedure TAppService.Install;
320349
end;
321350
//service interacts with desktop
322351
if fDesktopInteraction then servicetype := SERVICE_WIN32_OWN_PROCESS and SERVICE_INTERACTIVE_PROCESS
323-
else servicetype := SERVICE_WIN32_OWN_PROCESS;
352+
else servicetype := SERVICE_WIN32_OWN_PROCESS;
324353
//service load order
325354
if fLoadOrderGroup.IsEmpty then svcloadgroup := nil
326355
else svcloadgroup := PChar(fLoadOrderGroup);
@@ -333,7 +362,7 @@ procedure TAppService.Install;
333362
//service user password
334363
if fUserPass.IsEmpty then svcuserpass := nil
335364
else svcuserpass := PChar(fUserPass);
336-
365+
337366
fSvHandle := CreateService(fSCMHandle,
338367
PChar(fServiceName),
339368
PChar(fDisplayName),
@@ -348,6 +377,9 @@ procedure TAppService.Install;
348377
svcusername, //user
349378
svcuserpass); //password
350379

380+
if Length(fServiceDescription) > 0 then
381+
SetServiceDescription;
382+
351383
if fSvHandle <> 0 then
352384
begin
353385
if fSilent then Writeln(Format(cInstallMsg,[fServiceName]))
@@ -364,7 +396,7 @@ procedure TAppService.Help;
364396
WriteLn(' [/instance:<service name>]'+#9+'Install service with a custom name');
365397
end
366398
else Writeln(Format('%s [/console] [/install] [/remove] [/h] [/help]',[ExtractFileName(ParamStr(0))]));
367-
WriteLn(' [/console]'+#9#9#9+'Force run as a console application (when runned from another service)');
399+
WriteLn(' [/console]'+#9#9#9+'Force run as a console application (when run from another service)');
368400
WriteLn(' [/install]'+#9#9#9+'Install as a service');
369401
WriteLn(' [/remove]'+#9#9#9+'Remove service');
370402
WriteLn(' [/h /help]'+#9#9#9+'This help');

0 commit comments

Comments
 (0)