views:

1200

answers:

1

Hi,

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!

+1  A: 

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.

Bermo
thanks! - do you know how to get the service to auto-start as well?
db1234
No sorry, never had to do that before. I'd add it as another question if I was you.
Bermo
PrinterMonitorServiceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic this will do this
JKS
ServiceInstaller's StartType Property has options for service as "Automatic","Manual" and "Disabled"..this can be used to set service start mode.In my project i set it to automatic ,after installation in services list my service start property is automatic but not started immidiately after setup...how to also run service after setup??
dankyy1