Windows服务安装项目-以管理员身份运行服务 [英] Windows Service setup project - run service as administrator

查看:581
本文介绍了Windows服务安装项目-以管理员身份运行服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务的安装项目(.net 3.5,Visual Studio 2008)。

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

Windows服务需要在管理员帐户下运行,有人知道我如何获得安装项目来将Windows服务的用户登录身份设置设置为安装过程的一部分?

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.

谢谢!

推荐答案

您应该能够在安装程序的 InitializeComponent()方法中添加新的 ServiceProcessInstaller 。此类可让您设置希望服务运行的帐户类型,用户名和密码。例如:

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.

这篇关于Windows服务安装项目-以管理员身份运行服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆