Search This Blog

Install the Windows Service

Windows Services are different than normal Windows based applications. It is not possible to run a Windows Service by simply running an EXE. The Windows Service should be installed by using the InstallUtil.exe provided with the .NET Framework or through a deployment project such as a Microsoft Installer (MSI) file.

Add an Installer
Having created the Windows Service will not be enough for the InstallUtil program to be able to install the service. You must also add an Installer to your Windows Service so that the InstallUtil, or any other installation program, knows what configuration settings to apply to your service.

Switch to the design view for the service
Right click and select Add Installer
Switch to the design view of the ProjectInstaller that is added
Set the properties of the serviceInstaller1 component
ServiceName = My Sample Service
StartType = Automatic
Set the properties of the serviceProcessInstaller1 component
Account = LocalSystem
Build the Solution
The following code contained in the ProjectInstaller.cs source file was automatically generated by Visual Studio after having completed the steps above.

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace CodeGuru.MyWindowsService
{
///
/// Summary description for ProjectInstaller.
///

[RunInstaller(true)]
public class ProjectInstaller :
System.Configuration.Install.Installer
{
private System.ServiceProcess.ServiceProcessInstaller
serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public ProjectInstaller()
{
// This call is required by the Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
}

#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

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.ServiceName = "My Sample Service";
this.serviceInstaller1.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
//
// ProjectInstaller
//
this.Installers.AddRange(new
System.Configuration.Install.Installer[]
{this.serviceProcessInstaller1, this.serviceInstaller1});
}
#endregion
}
}

1 comments:

Karthi Kesavan said...

Hi,

I had installed my WindowsService using InstallUtil, I got Logs

Any Idea to this WindowsService.Installlog

Installing assembly 'D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe
logfile = D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe assembly.
Committing assembly 'D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe'.
Affected parameters are:
logtoconsole =
assemblypath = D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe
logfile = D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.InstallLog
No public installers with the RunInstallerAttribute.Yes attribute could be found in the D:\MyPrograms\WindowsService\WindowsService\bin\Debug\WindowsService.exe assembly.
Remove InstallState file because there are no installers.

Thanks for your help in advance.

Regards,
Karthi