Install Windows Service Using Setup Project

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to install a Windows Service programmatically using a setup
project. I've successfully installed the service using InstallUtil, but I
want to make life easy for my customers, so I'm trying to figure out how to
do it with a setup project. I've scoured the web trying to find something,
but have been unsuccessful. Can anyone point me in the right direction?
 
Hey Matt,

Since you can install your service using InstallUtil.exe, I assume that you
have already added an installer to your service project. To install the
service from your setup project, all you have to do is add the primary
project output for your service to all 4 custom actions for your setup
project. This will install the service but it will not start the service.
If you also want you start the service from the setup project, you need to
override the Install method in the installer class:

public override void Install(IDictionary stateSaver)
{
base.Install (stateSaver);

System.ServiceProcess.ServiceController sc
= new
System.ServiceProcess.ServiceController("ServerWatchService");
sc.Start();
}

HTH, Jakob.
 
Back
Top