Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically set the user account for a windows service?

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?

like image 633
swolff1978 Avatar asked Aug 05 '09 15:08

swolff1978


3 Answers

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>;
    }
like image 86
Chill Avatar answered Oct 23 '22 05:10

Chill


Take a look at System.ServiceProcess.ServiceProcessInstaller

like image 39
MattH Avatar answered Oct 23 '22 06:10

MattH


Take a look at DynamicInstaller from CodeProject

like image 1
Shay Erlichmen Avatar answered Oct 23 '22 04:10

Shay Erlichmen