0

In my VS solution I have two projects: a windows service and a win app with one form and two buttons (install/uninstall and start/stop). I have followed Matt Davis tutorial

How to make a .NET Windows Service start right after the installation?

for creating ProjectInstaller, now I am confused how to actually fire up installation upon button click, which is in another project (win app). Id appreciate any help.

Community
  • 1
  • 1
1atera1usz
  • 133
  • 1
  • 15

2 Answers2

0

This is untested but if you add a reference in the win app to System.Configuration.Install. This assembly has all the code in the to install services. Then from code in your win app you can add something like this:

public void InstallService(string pathToAssembly)
{
    System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { pathToAssembly });
}

To use it, you only need to know the path to the exe file of your service that inherits from ServiceBase.

DavidG
  • 113,891
  • 12
  • 217
  • 223
0

My tutorial is geared to install the service from the command line, not from another application. That said, I think it'd be easy enough to do the following (although I have not tested it):

string pathToServiceExecutable = ...;  // specify the full path to your service
System.Diagnostics.Process.Start(pathToServiceExecutable, "-install");
Matt Davis
  • 45,297
  • 16
  • 93
  • 124