Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service setup project - run service as administrator

Tags:

I've got a setup project for a Windows Service (.net 3.5, visual studio 2008).

The Windows Service needs to be run under the Administrator account, does anyone know how I can get the Setup Project to set the "user to log on as" setting for the windows service as part of the setup process?

At the moment I have to manually right click on the service and set it to log on as the administrator everytime I update the service.

Thanks!

like image 633
db1234 Avatar asked Nov 07 '09 10:11

db1234


People also ask

How do I setup a Windows project service?

Create Setup Project for Window Service Open a dialog box, go to left pane under Installed Templates > Other Project Types > Setup and Deployment > Visual Studio Installer and go to the right pane and select the project as a “Setup Project” and click on the OK button.

How do I add project installer to Windows Service?

In Solution Explorer, access Design view for the service for which you want to add an installation component. Click the background of the designer to select the service itself, rather than any of its contents. With the designer in focus, right-click, and then click Add Installer.


1 Answers

You should be able to add a new ServiceProcessInstaller in the InitializeComponent() method of your installer. This class will allow you to set account type, username, and password that you want the service to run as. For example:

this.Installers.Add(
        new System.ServiceProcess.ServiceProcessInstaller()
            {
                Account = ServiceAccount.User,
                Username = @"domain\username",
                Password = "password"
            });

If you don't want to hardcode a password into your setup project, then leave it blank and a popup dialog should appear asking for this during install.

like image 195
Bermo Avatar answered Oct 15 '22 23:10

Bermo