I'll start with an example: Apache web server (under Windows) has a nice feature: it can be both run as a standalone application (with current users privileges), and that it can be installed and run as a windows service directly (as local system account), using same executable.
In order for application to be run as a standalone app, all it needs to do is along the lines of having static public Main() in some public class.
In order for application to be installable and runnable as service, it has to implement ServiceBase and Installer classes in certain way. But, if application like this is run as standalone app, it will show message box.
How can this Apache-like mode of operation be achieved? I believe solution is simple, but I don't really have an idea where to start.
Piece of code that follows is used to invoke service. Can it be modified to allow standalone usage?
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service() // defined elsewhere as Service : ServiceBase
};
ServiceBase.Run(ServicesToRun);
}
}
My language of choice is C#.
Edit: Currently, I have abstracted common code into separate assembly (let's call it Library.dll), and I have two executables: Console.exe and Service.exe, which are standalone and windows service applications, respectively, and both are just means to invoking Library.dll.
My goal is to merge those two executables into one, that will still call to Library.dll.