如何在不提示输入用户 ID、密码、确认密码的情况下允许安装服务

How to allow the service to install without prompting for the User ID, Password, Confirm Password

当我尝试从 Visual Studio 命令提示符安装服务 (installutil service.exe) 时,它会提示设置用户 ID、密码以安装服务。可以参考凭证提示截图(link)

picture of prompting for credentials while installing service.

这是在 C#.net 中使用 .NET 4.0 框架完成的。

我在发布这个问题之前搜索过这个,最后将凭据设置为空(请参考下面粘贴的代码)。但是没用。

private void InitializeComponent()
    {
        this.StockManagementProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
        this.StockManagementInstaller1 = new System.ServiceProcess.ServiceInstaller();
        // 
        // StockManagementProcessInstaller1
        // 
        this.StockManagementProcessInstaller1.Password = null;
        this.StockManagementProcessInstaller1.Username = null;
        // 
        // StockManagementInstaller1
        // 
        this.StockManagementInstaller1.DisplayName = "StockManagement";
        this.StockManagementInstaller1.ServiceName = "StockManagement";
        this.StockManagementInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
        // 
        // ProjectInstaller
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.StockManagementProcessInstaller1,
        this.StockManagementInstaller1});

    }

任何人都可以帮助我如何摆脱它并毫无问题地安装服务?

在没有密码提示的情况下将您的服务安装为本地服务,只需执行以下操作:

// StockManagementProcessInstaller1
// 
this.StockManagementProcessInstaller1.Account = ServiceAccount.LocalService;
this.StockManagementProcessInstaller1.Password = null;
this.StockManagementProcessInstaller1.Username = null;

而不是:

// StockManagementProcessInstaller1
// 
this.StockManagementProcessInstaller1.Password = null;
this.StockManagementProcessInstaller1.Username = null;

希望能支持你的问题。