Accessing the Windows Startup Options service from Topshelf

I added command line support to my topshelf program like this:

HostFactory.Run(hostConfigurator =>
{
    hostConfigurator.AddCommandLineDefinition("params", f => { startParams = f; });    
    hostConfigurator.ApplyCommandLine(); 
}

      

And it works great.

When I install it as a service, I was hoping that in the "Installed Services" startup options, it would work for the same purpose, but it doesn't.

Can anyone tell me how to access the "startup options" from TopShelf?

I want to install the same service multiple times (with different instance names) that differ in startup parameters and I also want to use it to pass test values.

I am guessing that just accessing this software for a standard service will probably point me in the right direction.

thank.

+3


source to share


1 answer


The parameters related to the installation of the Service, such as servicename, description, instancename, etc., can be accessed as follows

HostFactory.Run(x =>
{
    x.Service((ServiceConfigurator<MyService> s) =>
    {
        s.ConstructUsing(settings =>
        {
            var instanceName= settings.InstanceName;
                return new MyService();
        });
    }
}

      

Or if your MyService implements ServiceControl



        HostFactory.Run(x =>
        {
            x.Service<MyService>((s) =>
            {
                var instanceName= s.InstanceName;

                return new MyService();
            });
         }
/***************************/

class MyService : ServiceControl
{
    public bool Start(HostControl hostControl) {  }

    public bool Stop(HostControl hostControl)  {  }
}

      

I'm not sure what you mean by "Start Parameters", if the above is not what you want, try to explain with an example pseudocode what you are trying to achieve.

+1


source







All Articles