Reputation: 532
I have a Visual Studio Setup Project used to install a Windows service. The service is set to run automatically and it is installing fine at this point by adding my service as a custom action. However, I would like the installer to start the service once the installation is complete. Is this possible?
On a related note, do I need to manually stop the service on uninstalls and/or upgrades?
Upvotes: 4
Views: 4244
Reputation: 736
Override below custom action handler to start windows service after the installation. Though you set service property type=Automatic, the service won't start unless we explicitly start:
protected override void OnAfterInstall(IDictionary savedState)
{
using (var sc = new ServiceController(serviceInstaller1.ServiceName))
{
sc.Start();
}
}
Visual Studio installer is not stopping FileInUse prompt though we stop the service using custom action for uninstall/upgrade. Seems like VS Installer doesn't have much sophistication to change the sequence of installer because of that we couldn't control this behavior. But, it is better idea to stop the service for uninstall/upgrades.
Upvotes: 3
Reputation: 10993
You can use a custom action too, for starting/stopping the service. From your custom action you just need to call the following utility: http://technet.microsoft.com/en-us/library/cc736564(v=ws.10).aspx
Yes, for upgrades/uninstalls you should stop the service before the files are removed, so you avoid a "Files in Use" prompt from the OS.
Upvotes: 1