I have an application that I want to run as a Windows Service. Following instructions provided in this MSDN doc page (I need to host a WCF service, so the procedure also details this part), I can do that, and if I implement the example service it is all right. I use installutil.exe
utility and can install and uninstall my application as a Windows Service.
However I need to install more service of the same application on my local machine. So I need to give them different System.ServiceProcess.ServiceBase.ServiceName
s! So consider again the installation code:
[RunInstaller(true)]
public class ProjectInstaller : Installer {
private ServiceProcessInstaller process;
private ServiceInstaller service;
public ProjectInstaller() {
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = /* NEED TO PUT HERE THE NAME!!! */;
Installers.Add(process);
Installers.Add(service);
}
}
Is there a way for me to pass the name of the service when calling installutil.exe
?
How to approach to this problem? I also tried using the App.Config
file and doing something like this:
public ProjectInstaller() {
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = System.Configuration.ConfigurationManager.
AppSettings["SrvName"];
Installers.Add(process);
Installers.Add(service);
}
But of course it did not work, this file is called when the application runs!!!
You can open config file for executing assembly. If your installer code is placed into main service exe file - it will be your app.config. Otherwise, config file need to be named [assemblyname].dll.config.
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
var path = Assembly.GetExecutingAssembly().Location;
var config = ConfigurationManager.OpenExeConfiguration(path);
service.ServiceName = config.AppSettings.Settings["ServiceName"];
Installers.Add(process);
Installers.Add(service);
Also, this article explains how to pass installutil parameters explicitly through command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With