views:

2760

answers:

4

I have a .Net Windows service. I can create an installer to install the windows service.

Basically it has to do the following.

  1. Pack installutil.exe (Is it required?)
  2. run installutil.exe MyService.exe
  3. net start MyService

Also, I have to provide an uninstaller which runs:

  1. installutil.exe /u MyService.exe

How to do these using Inno Setup

A: 

I think you need to use the [Run] section. See here

Preet Sangha
+22  A: 

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:

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"
lubos hasko
Thanks a lot! That worked like magic. One more clarification. How to run a command like net start WinServ in the Inno Script?
iJeeves
you can try `Filename: "net.exe"; Parameters: "start WinServ"`. if it doesn't work, you could just add one more switch --start to your c# application and start windows service directly from the program by using ServiceController class (http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx).
lubos hasko
yeah that too worked! --start with ServiceController class.Thanks again!
iJeeves
+1 Nice. See also http://stackoverflow.com/questions/255056/install-a-net-windows-service-without-installutil-exe
Ruben Bartelink
A: 

If you want to avoid reboots when the user upgrades then you need to stop the service before copying the exe and start again after.

There are some script functions to do this at http://www.vincenzo.net/isxkb/index.php?title=Service

Tony Edgecombe
A: 

You can use

Exec(
    ExpandConstant('{sys}\sc.exe'),
    ExpandConstant('create "MyService" binPath= {app}\MyService.exe start= auto DisplayName= "My Service" obj= LocalSystem'), 
    '', 
    SW_HIDE, 
    ewWaitUntilTerminated, 
    ResultCode
    )

to create a service. See "sc.exe" on how to start, stop, check service status, delete service, etc.

Steven