c# windows 服务安装程序提示用户输入凭据

c# windows service installer prompt user for credentials

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

我也尝试过以最低限度做到这一点。 我创建了一个新的 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});

    }

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

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