dasMulli / dotnet-win32-service

Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
MIT License
451 stars 57 forks source link

Request: Support adding service dependencies #84

Closed WantStuff closed 5 years ago

WantStuff commented 5 years ago

I'd like to be able to a service start dependencies when creating a new service.

In case it helps, my work around for this is to add them independently using the below:

public static void SetDependencies(ServiceDefinition serviceDefinition, string[] dependencies)
{
    if (dependencies == null || !dependencies.Any())
        return;

    var dependenciesConcat = string.Join('\0', dependencies);
    var serviceHandle = new ServiceController(serviceDefinition.ServiceName).ServiceHandle;
    if (!Win32.ChangeServiceConfig(
        serviceHandle,
        Win32.SERVICE_NO_CHANGE,
        Win32.SERVICE_NO_CHANGE,
        Win32.SERVICE_NO_CHANGE,
        null,
        null,
        IntPtr.Zero,
        dependenciesConcat,
        null,
        null,
        null))
    {
        throw new Win32Exception();
    }
}
WantStuff commented 5 years ago

Apologies, I have just seen this is already a feature request under #70