【问题标题】:c# windows service installer prompt user for credentialsc# windows服务安装程序提示用户输入凭据
【发布时间】:2015-06-07 17:43:07
【问题描述】:

我想让安装程序(在安装过程中)提示用户输入凭据。我实际上希望它提示用户。 我已经完成了我在此处阅读的大多数问题/答案中看到的内容,将帐户设置为用户。

我也尝试过以最低限度来做到这一点。 我创建了一个新的 Windows 服务项目。然后我创建了一个 Visual Studio 安装程序(安装项目)。

在windows服务项目中,在.cs文件(我称之为ProjectInstaller)中,右键点击主设计页面,点击添加安装程序,出现了两个安装程序。在我的 ProjectInstaller.Designer.cs 中,我在 InitializeComponent 方法中添加了这行代码

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;

然后我转到我的安装程序设置项目,右键单击,将主输出设置为 Windows 服务项目,就是这样。编译所有内容并运行安装程序文件,但它没有提示我输入凭据。

我不知道它是否会有所帮助,但这是整个 InitializeComponent 方法

    private void InitializeComponent()
    {
        this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
        this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
        this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
        // 
        // serviceProcessInstaller1
        // 
        this.serviceProcessInstaller1.Password = null;
        this.serviceProcessInstaller1.Username = null;
        this.serviceProcessInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_AfterInstall);
        // 
        // serviceInstaller1
        // 
        this.serviceInstaller1.ServiceName = "Service1";
        this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall);
        // 
        // ProjectInstaller
        // 
        this.Installers.AddRange(new System.Configuration.Install.Installer[] {
        this.serviceProcessInstaller1,
        this.serviceInstaller1});

    }

我缺少什么以便我的安装程序提示用户输入凭据?

【问题讨论】:

    标签: c# windows service installation


    【解决方案1】:

    默认情况下您不能这样做。您可以做的是使用新的自定义页面创建 WiX 设置,让用户输入服务帐户的凭据。

    【讨论】:

    • 你能解释一下为什么我们不能默认这样做吗?视觉工作室的版本重要吗?我在 Visual Studio 2013 上运行
    • 因为提示输入凭据不是服务安装程序的功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多