Enabling .NET studio Windows Service project to work with installutil.exe
I was just trying to create a simple C#.NET windows service with visual studio .NET 2005. After selecting Windows Service template, I got the template code for common required service infrastructure lik, OnStart() and OnStop() methods.
I added my custom code in necessary methods and tried to register it using installutil.exe but was not able to see that in Service Control Manager.
Actually we have to add the ServiceInstaller file to the project and add some code to that file.
We have to add following two member variable for that ServiceInstaller template class,
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
We have to populate InitializeComponent method with following code..
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
//
// serviceInstaller1
//
this.serviceInstaller1.DisplayName = "COMTestService";
this.serviceInstaller1.ServiceName = "COMTestService";
//
// ProjectInstaller
//
this.Installers.AddRange( new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1} );