ChrisA
ChrisA

Reputation: 4193

How to edit the "log on as" user in a .Net Windows Service

I plan to write a windows service to initiate all the business processing, and a Windows Forms app to do all its configuration.

Can the windows user under which the service runs be edited in code as part of the configuration?

Upvotes: 0

Views: 309

Answers (3)

OJ.
OJ.

Reputation: 29401

You will need to use the ServiceInstaller class in conjuction with the ServiceProcessInstaller class. To set the account to run the service under, you need to set the Account property.

Upvotes: 1

Philippe Leybaert
Philippe Leybaert

Reputation: 171774

The account is usually set by the service installer. This is done via the ServiceProcessInstaller component

The properties are:

  • ServiceAccount
  • UserName
  • Password

You should be able to set them using the VS designer

If you want to change an existing service's startup account using a separate WinForms application, you have to fiddle with the registry I think (but I don't know what registry keys to change)

Upvotes: 1

adrianbanks
adrianbanks

Reputation: 82944

It can be altered programatically when the service is installed. Have a look at the System.ServiceProcess.ServiceProcessInstaller class. It has properties to set the the account, username and password. You need to make an instance of this class with the correct settings and add it to the Installers collection of your custom (System.Configuration.Install.Installer) installer.

Upvotes: 1

Related Questions