1

I have written a Windows Service in VisualStudio (c#) and added a Setup Wizard. After the successful installation, I have to register the Service via installutil.

Is it possible to perform this step automatically and ask for a ServiceAccount through the Installation Steps?

Hendriks91
  • 81
  • 5
  • 2
    Could you provide more info on this 'setup wizard'? – sommmen Oct 09 '20 at 07:28
  • 1
    Yes its possible -- and depends on install wizard, if you are using Microsoft install wizard for visual studio you can add post install action where you can specify the installutil command that will run and will install your service too – Muhammad Waqas Aziz Oct 09 '20 at 07:48
  • yes, this is a Visual Studio Setup Installer Project which i added and configured to install the Service. This works so far that all required files are copied but the Service is not registered – Hendriks91 Oct 09 '20 at 07:52
  • Hello @Muhammad Waqas Aziz, yes this is a Microsoft Install Wizard for Visual Studio. Could you tell me how to do this with installation and how to remove with uninstall? :) – Hendriks91 Oct 09 '20 at 07:56
  • i can give you an idea on it – Muhammad Waqas Aziz Oct 09 '20 at 09:24
  • If using .Net Framework, check System.Configuration.Install.[Installer](https://learn.microsoft.com/en-us/dotnet/api/system.configuration.install.installer?view=netframework-4.5) With it, there is no need for InstallUtil. – aamartin2k Oct 09 '20 at 15:27

1 Answers1

1

You have to add a console project to your solution

and in the main method you will write the below code remember to replace "Your service file.exe" with the name of your service exe file

Process.Start(Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v4.0.30319\installutil", $"\"{Environment.CurrentDirectory}\\Your service file.exe\"");

after adding above project

When you right click on your added setup project, you will see view menu, in view menu there will be custom action link click it, in window that is appeared right click install and click add custom action, then double click Application Folder then click Add Output button on the right and then select the console project from drop-down menu then select primary out put then click ok and we are done.

KEEP IN MIND YOU NEED TO RUN THE INSTALATION SETUP AS ADMINISTRATOR