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.
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
.
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.