Create, delete, stop, start, and change configurations of Windows services.
The ISvcUtils interface provides a comprehensive set of functionalities for managing Windows services. This component simplifies service-related operations, making it easy to work with service configurations, installations, and more.
Forget about creating .bat files and invoking everything through ShellExecute; now you can do all of that directly in Delphi.
To use the component is easy, simply add the "src" folder from this repository to the Library path settings in your Delphi or to the Search Path of your project. After that, you only need to declare the "SvcUtils.IntF" unit in the Delphi's uses clause.
var
LService: ISvcUtils;
begin
LService:= TSvcUtils.New;
if LService.GetServiceByName('MyService').isStarted then
ShowMessage('The service is running');
end;
TSvcUtils.New.
.InstallService('MyService', 'My Service Display Name',
TSvcType.ServiceWin32OwnProcess, //default service instalation
TSvcStartType.ServiceDemandStart, //start manually
TSvcErrorControl.ServiceErrorNormal,
'C:\myservice.exe', //Service binary path, the path can also include arguments for an auto-start service. For example, "d:\myshare\myservice.exe arg1 arg2"
'', nil).ServiceStart;
or
TSvcUtils.New.
.GetServiceByName('MyService').ServiceStart;
Get the Service Info
var
LSvcInfo: ISvcInfo;
begin
LSvcInfo:= TSvcUtils.New.
.InstallService('MyService', 'My Service Display Name',
TSvcType.ServiceWin32OwnProcess, //default service instalation
TSvcStartType.ServiceDemandStart, //start manually
TSvcErrorControl.ServiceErrorNormal,
'C:\myservice.exe', //Service binary path
'', nil);
// with LSvcInfo you can do a lot of things, stop, start, change configuration etc...
// Service description can be set calling LSvcInfo.ChangeDescription('My description');
end;
if TSvcUtils.New.UninstallService('MyService') then
ShowMessage('Done!');
TSvcUtils.New
.GetServiceByName('MyService')
.ChangeServiceType()
.ChangeServiceStart()
.ChangeServiceErrorControl()
.ChangeBinaryPath()
.ChangeAccountName()
.ChangeDisplayName()
.ChangeDescription();
Make sure your application has administrative privileges.