Windows Service setup project - run service as adm

2020-07-15 02:55发布

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条回答
走好不送
2楼-- · 2020-07-15 03:29

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.

查看更多
登录 后发表回答