swolff1978
swolff1978

Reputation: 1865

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?

Upvotes: 9

Views: 14355

Answers (4)

Chill
Chill

Reputation: 61

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>;
    }

Upvotes: 6

user138512
user138512

Reputation:

There is a bit about setting service parameters and stuff in A Windows Service without a template Its on page 5 in the bit about customising a service.

Upvotes: 0

MattH
MattH

Reputation: 1975

Take a look at System.ServiceProcess.ServiceProcessInstaller

Upvotes: 3

Shay Erlichmen
Shay Erlichmen

Reputation: 31928

Take a look at DynamicInstaller from CodeProject

Upvotes: 1

Related Questions