Credentials when Installing Windows Service

Keith picture Keith · Feb 12, 2010 · Viewed 68.7k times · Source

I am attempting to install a C# windows service project using a VisualStudio.Net deployment project.

To run the deployment project I right-click and select "install" from the context menu, the install wizard runs and eventually prompts me with a "Set Service Login" dialog which asks for username & password.

When I install a service using the sc utility from the command line, I don't have to provide credentials.

Do I have to create a login just for this service? I'd prefer to use "Local System" or "Network Service" (not sure what the difference is) as other services do.

Answer

anthares picture anthares · Feb 12, 2010

Add this code to your private void InitializeComponent() method in projectInstaller.Designer.cs file in your windows service project.

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

if the definition of you process installer is:

private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;