Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup for Windows service?

I have a .Net Windows service. I want to create an installer to install that windows service.

Basically, it has to do the following:

  1. Pack installutil.exe (Is it required?)
  2. Run installutil.exe MyService.exe
  3. Start MyService

Also, I want to provide an uninstaller which runs the following command:

installutil.exe /u MyService.exe 

How to do these using Inno Setup?

like image 423
softwarematter Avatar asked Sep 20 '09 01:09

softwarematter


People also ask

What is Inno Setup used for?

Inno Setup is a free installer for Windows programs by Jordan Russell and Martijn Laan. First introduced in 1997, Inno Setup today rivals and even surpasses many commercial installers in feature set and stability. Learn more about what Inno Setup can do. Get the latest version of Inno Setup here.

What is an Inno Setup file?

Inno Setup is a free software script-driven installation system created in Delphi by Jordan Russell. The first version was released in 1997. Inno Setup. Screenshot of the Inno Setup IDE running on Windows 7. Developer(s)


2 Answers

You don't need installutil.exe and probably you don't even have rights to redistribute it.

Here is the way I'm doing it in my application:

using System; using System.Collections.Generic; using System.Configuration.Install;  using System.IO; using System.Linq; using System.Reflection;  using System.ServiceProcess; using System.Text;  static void Main(string[] args) {     if (System.Environment.UserInteractive)     {         string parameter = string.Concat(args);         switch (parameter)         {             case "--install":                 ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });                 break;             case "--uninstall":                 ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });                 break;         }     }     else     {         ServiceBase.Run(new WindowsService());     } } 

Basically you can have your service to install/uninstall on its own by using ManagedInstallerClass as shown in my example.

Then it's just matter of adding into your InnoSetup script something like this:

[Run] Filename: "{app}\MYSERVICE.EXE"; Parameters: "--install"  [UninstallRun] Filename: "{app}\MYSERVICE.EXE"; Parameters: "--uninstall" 
like image 71
lubos hasko Avatar answered Sep 21 '22 02:09

lubos hasko


Here's how i did it:

Exec(ExpandConstant('{dotnet40}\InstallUtil.exe'), ServiceLocation, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); 

Apparently, Inno setup has the following constants for referencing the .NET folder on your system:

  • {dotnet11}
  • {dotnet20}
  • {dotnet2032}
  • {dotnet2064}
  • {dotnet40}
  • {dotnet4032}
  • {dotnet4064}

More information available here.

like image 41
breez Avatar answered Sep 17 '22 02:09

breez