Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service Choose User or System Account on Install

When installing a windows service, is there a way to let the user installing choose between a specific user account and a computer account, such as LocalSystem? I see how to do this at build time through service installer properties, but not during install.

like image 913
AdamC Avatar asked Dec 15 '10 18:12

AdamC


People also ask

What user does a Windows service run under?

A service should only run under the LocalSystem account if the service requires administrative privileges or must act as part of the operating system on the local computer. Be aware that the service installer should, by default, set up the service to run under a domain user account.

How do I change the user for service running?

Open the Administrative Tools > Services window on your Windows server. Stop the JetBrains YouTrack service. Open the Properties > Log On dialog. Change the service user account to the target user account.

How do I install a Windows service with a different name?

In case you need the same service running on the same host but with different configuration, logically you would use same code just copy the service folder with different configuration and use installutil to install service with a different name.


1 Answers

@Doobi, @Eric, in my experience (Win7Home 64-bit, VS2010Express, not on a domain)

 processInstaller.Account = ServiceAccount.LocalService;
 processInstaller.Username = null;
 processInstaller.Password = null;

will install the service as LocalService without a password prompt.

To install the service as a local user account (and provide a password prompt to enable the user to supply the credentials) I had to use:

 this.serviceProcessInstaller.Account =System.ServiceProcess.ServiceAccount.User;
 this.serviceProcessInstaller.Password = null;
 this.serviceProcessInstaller.Username = null;

The important step I had to take to get the service installed is to put the computer name in the credentials dialog box, ie MYPC\dave instead of dave. I was surprised that I'd have to do this as it's not on a domain. I've added this comment as no other posts I've seen about this mention having to prefix the username with the PC name.

like image 193
Badgerspot Avatar answered Nov 07 '22 02:11

Badgerspot