Is it possible to programmatically set the user account for a windows service?
12,773
Solution 1
Take a look at System.ServiceProcess.ServiceProcessInstaller
Solution 2
The below addition to a project installer will assign the service Log On information during installation.
public ProjectInstaller()
{
InitializeComponent();
serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.<account type>;
serviceProcessInstaller1.Username = <domain\userId>;
serviceProcessInstaller1.Password = <password>;
}
Solution 3
Take a look at DynamicInstaller from CodeProject
Author by
swolff1978
Trying to learn best practices and become a more well rounded programmer. Suggestions welcome!
Updated on June 30, 2022Comments
-
swolff1978 almost 2 years
I have created a windows service that has the Account set to user. Which means that when I install the service I need to pass a user name and password. Is there a way to set these maybe in the ProjectInstaller class maybe in the BeforeInstall event? if so HOW?
-
Adam Neal about 12 yearsCan you use this to set the username & password at runtime (rather than compile-time)? Wouldn't you need to be able to get to the installers that are already compiled into your service executable? I'll probably have to go the WMI route instead.
-
MattH about 12 yearsYour service can have its own installer class that inherits from "System.Configuration.Install.Installer". We use this inherited class and associate a form with it. The form comes up during the install and prompts for various things, including user/password. Then in the Installer class you override OnBeforeInstall and set Me.ServiceProcessInstaller1.Username.
-
Kiquenet almost 10 yearsAnd modify windows service account for WinService that yet exists?
-
Viswa almost 9 yearsIf you do not specify an Account in code and have the ServiceProcessInstaller Property for Account set to User a form dialog will open during the installation that will allow the individual who performs the installation to specify a domain user account and password.
-
Grubsnik over 8 yearsshameless plug for something that isn't around any longer.