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

时间:2016-01-06 05:33:11

标签: c# visual-studio-2010 windows-services

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

picture of prompting for credentials while installing service.

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

我之前发布过这个问题并最终将凭据设置为null(请参阅下面粘贴的代码)。但它没有用。

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});

    }

任何人都可以帮我解决这个问题并安装服务没有任何问题吗?

1 个答案:

答案 0 :(得分:1)

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

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

而不是:

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

我希望能够支持你的问题。