I want to deploy a single exe which provides a web service, and be able to start it multiple times (each as a separate Windows service). Each instance of the exe needs to be able to load a different configuration file (e.g. so it can listen on a different port, or use a different database).
Ideally, I don't want to have to install the exe in multiple folders, just have multiple configuration files.
However there doesn't seem to be a way of finding which service name Windows is starting.
I have looked at How can a Windows Service determine its ServiceName? but it doesn't seem to work for me, because during startup the process id for the service being started is 0.
I guess I am asking too soon or something. My code does the following:
Main sets the current directory and constructs a WebService object (a subclass of ServiceBase)
The WebService object constructor now needs to set its ServiceName property, and uses the code in How can a Windows Service determine its ServiceName? to try to find the correct name. However, at this point the processid of the correct servicename is still 0.
Following this, Main will build an array of (1) ServiceBase containing the WebService object, and call ServiceBase.Run on the array. The service name needs to be correct by this point, because it may not be changed once the service is running.