program service_change_security;
{$APPTYPE CONSOLE}
uses
Windows, SysUtils, NTServiceMan, NTException, AbstrSec, WinSVC;
var
ServiceMan: TNTServiceManager;
List: TAccessList;
Mask: DWORD;
begin
ServiceMan := TNTServiceManager.Create(nil);
try
// Uncomment this block to configure service on remote host
// ServiceMan.LogonAs.UserName := 'MyDomain\MyUserName';
// ServiceMan.LogonAs.Password := 'MyPassword';
// if TargetHost <> '' then ServiceMan.MachineName := '\\'+ TargetHost;
// if (ServiceMan.MachineName <> '') and (ServiceMan.ConnectIPC <> 0) then
// writeln('Warning: could not use the provided credentials.');
ServiceMan.ServiceName := 'Alerter';
try
ServiceMan.ActiveManager := true;
ServiceMan.ServiceAccess := SERVICE_QUERY_CONFIG or SERVICE_CHANGE_CONFIG;
ServiceMan.ActiveService := true;
List := ServiceMan.AccessList;
List.BeginUpdate;
try
// give Administrator full access, everyone else can
// only read properties and start the service
List.Clear;
Mask := SERVICE_QUERY_CONFIG or SERVICE_START or READ_CONTROL;
List.Add('Everyone', Mask, [], actAccessAllowed);
Mask := SERVICE_ALL_ACCESS;
List.Add('Administrator', Mask, [], actAccessAllowed);
finally
List.EndUpdate;
end;
except
On e: ENTException do
begin
writeln(e.message);
end;
end;
finally
ServiceMan.Free;
end;
end.
|