C# – Install Windows Service created in Visual Studio

cinstallutilservicewindowswindows-services

When I create a new Windows Service in Visual Studio 2010, I get the message stating to use InstallUtil and net start to run the service.

I have tried the following steps:

  1. Create new project File -> New -> Project -> Windows Service
  2. Project Name: TestService
  3. Build project as is (Service1 constructor, OnStart, OnStop)
  4. Open command prompt, run "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" TestService.exe
  5. Run net start TestService.

Output of step 4

Running a transacted installation.

Beginning the Install phase of the installation.

See the contents of the log file for the
C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe
assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio
2010\Projects\Tes
tService\TestService\obj\x86\Debug\TestService.InstallLog.

Installing assembly 'C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\T
estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute
could be found in the C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe
assembly.

The Install phase completed successfully, and the Commit phase is
beginning.

See the contents of the log file for the
C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe
assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio
2010\Projects\Tes
tService\TestService\obj\x86\Debug\TestService.InstallLog.

Committing assembly 'C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\T
estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute
could be found in the C:\Users\myusername\Documents\Visual Studio
2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe
assembly.

Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

Output of step 5

The service name is invalid.

More help is available by typing NET HELPMSG 2185.

Best Answer

You need to open the Service.cs file in the designer, right click it and choose the menu-option "Add Installer".

It won't install right out of the box... you need to create the installer class first.

Some reference on service installer:

How to: Add Installers to Your Service Application

Quite old... but this is what I am talking about:

Windows Services in C#: Adding the Installer (part 3)

By doing this, a ProjectInstaller.cs will be automaticaly created. Then you can double click this, enter the designer, and configure the components:

  • serviceInstaller1 has the properties of the service itself: Description, DisplayName, ServiceName and StartType are the most important.

  • serviceProcessInstaller1 has this important property: Account that is the account in which the service will run.

For example:

this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
Related Topic