You can always fall back to the good old WinAPI calls, although the amount of work involved is non-trivial. There is no requirement that .NET services be installed via a .NET-aware mechanism.
To install:
OpenSCManager
.CreateService
to register the service.ChangeServiceConfig2
to set a description.CloseServiceHandle
.To uninstall:
OpenSCManager
.OpenService
.DeleteService
on the handle returned by OpenService
.CloseServiceHandle
.The main reason I prefer this over using the ServiceInstaller
/ServiceProcessInstaller
is that you can register the service with your own custom command line arguments. For example, you might register it as "MyApp.exe -service"
, then if the user runs your app without any arguments you could offer them a UI to install/remove the service.
Running Reflector on ServiceInstaller
can fill in the details missing from this brief explanation.
P.S. Clearly this won't have "the same effect as calling: InstallUtil MyService.exe" - in particular, you won't be able to uninstall using InstallUtil. But it seems that perhaps this wasn't an actual stringent requirement for you.