Hand-E-Food
Hand-E-Food

Reputation: 12794

Stop a service before installation

I wrote an application that installs using the Visual Studio 2010 Setup Project. As part of its installation, my application installs and starts a Windows Service. No problems there.

When I release a new version of the application, the installer overwrites the contents of the application folder. Unfortunately, it cannot overwrite the service as it is already running.

How can I stop the service before the MSI starts copying files? I'm considering a custom bootstrapper (installer prerequisit) that doesn't install, but removes the service. Or can I use Orca to add an action before installation? Or do you know another way?

Upvotes: 3

Views: 6743

Answers (1)

Cosmin
Cosmin

Reputation: 21416

Usually this is done through service control operations. Basically, you need the Stop and Delete flags set for uninstall.

Another approach would be to use ServiceInstaller.Uninstall in a custom action to stop and remove the service.

If you want to avoid the files in use dialog, you can try this approach: Problem stopping Windows Service from Installer Class. Events fire too late

Upvotes: 4

Related Questions