ANiceSunset
ANiceSunset

Reputation: 63

c# windows service installer prompt user for credentials

I would like to have the installer (in the middle of installing) prompt the user for credentials. I actually want it to prompt the user. I've done what i've seen in most questions/answers i read here, set the account to user.

I've also tried to do it with the bare minimum. I created a new windows service project. I then created a Visual Studio Installer (setup project).

In the windows service project, in the .cs file (I called it ProjectInstaller), right clicked the main design page and clicked on Add Installer and it appeared two installer. In my ProjectInstaller.Designer.cs, I added this line of code in the InitializeComponent method

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

I then went to my Installer setup project, right click, set primary output to the windows service project and that's it. Compiled everything and ran the installer file but it didn't prompt me to enter in credentials.

I don't know if it'll help but this is the entire InitializeComponent method

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

    }

What am I missing so that my installer will prompt the user to enter credentials?

Upvotes: 0

Views: 1008

Answers (1)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56717

You can not do that by default. What you can do is create a WiX setup with a new custom page that lets the user enter credentials for the service account.

Upvotes: 1

Related Questions