I have a Windows service and an MSI installer (setup project) for it. The setup project has custom actions for install and uninstall with args of /install and /uninstall respectively.
I would like the service to start immediately after the install. All my service does is starts a process. When the service is stopped, it does process.Close();
.
I have tried doing
var sc = new ServiceController( "MyProcess" );
sc.Start();
The process starts, but the event log message saying the service has started doesn't show. When stopping I get the error Error stopping process: System.InvalidOperationException: No process is associated with this object.
.
If I don't use the service controller to start and use Services.msc instead, it works as expected when stopping.
Is there a way to have the process start immediately and have my start/stop methods work as expected?