Error in installing Windows service developed in .NET

C#Windows ServicesUser Accounts

C# Problem Overview


I have developed a windows service using C# and Visual Studio 2008. I have Windows XP SP2 installed on my machine. When I try to install the service using the installutil tool, after entering the username and password, I get the following error.

> An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The account name is invalid or does not exist, or the password is invalid for the account name specified.

But the user does exist. I had created the user through control panel → User accountsCreate new account.

The command I used for installing the service was:

installutil /i TestService.exe

How can I resolve the issue?

C# Solutions


Solution 1 - C#

If the account is a local user account, try to use .\username when installutil prompts for the username and password.

The .\ stands for local machine.

Services require a fully qualified username (with domain), so when installing you need to be explicit about local user accounts.

Solution 2 - C#

The account may also need to be given the "Log on as a service" account right; pass the SE_SERVICE_LOGON_NAME constant to the LsaAddAccountRights() API.

Solution 3 - C#

I solved this by changing ServiceProcessInstaller.Account to LocalSystem, and it works for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSambhaView Question on Stackoverflow
Solution 1 - C#OdedView Answer on Stackoverflow
Solution 2 - C#devstuffView Answer on Stackoverflow
Solution 3 - C#DeeppView Answer on Stackoverflow