Setup project - stop a service?

J

JamesB

I have a setup project that copies a bunch of files, a small management
program, and also another .exe (that is run by a custom action) to install
and start a service.

Works fine first time, but the second time (i.e a user upgrades) the
installer cannot overwrite the service .exe as it is in use. Is there any
way to get the setup project to stop the service before copying the files
etc?

Thanks!
 
G

Guest

Hi JamesB,

Try:
ServiceController sc = new ServiceController("ServiceName");
sc.Stop();

Hope this helps :)
 
J

JamesB

Adam Bieganski said:
Hi JamesB,

Try:
ServiceController sc = new ServiceController("ServiceName");
sc.Stop();
The code makes sense - but where can I put that in a setup project? (Sorry,
I'm not too clever at setup stuff!)
 
G

Guest

You have to create a class that inherits from
System.Configuration.Install.Installer - it can be in the same project as the
NT Service that you are installing.

Then you override then Install method and execute the service stopping code
in there, before calling the base Install implementation.

Something like this:

[RunInstaller(true)]
public class ProjectInstaller : Installer
{
public override void Install(IDictionary stateSaver)
{
// stop the service here
ServiceController ....

// now let the installer do its job
base.Install(stateSaver);
}
}


Cheers,
_____________
Adam Bieganski
http://godevelop.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top