MarkusStrobl
Posts: 10
Joined: Wed Jul 09, 2008 7:32 am

Installing service

Hi!

I'm currently evaluating Advanced Installer for the use with our products.

A major requirement is to install a service with a commandline parameter and start it afterwards (and do the opposite when uninstalling).

The service is a standard C++ service written using Win32API and can be installed with a call to the exe itself:

Install:

myservice.exe -i

Uninstall:

myservice.exe -u

Can this be achieved using Advanced Installer? I tried the Services-Tab but couldn't find a way to pass those installation-/deinstallation parameters (as Advanced Installer can't know on its own which commandline parameter causes the service to install/uninstall itself).

Also when using CustomActions i wasn't successful so far.

Thanks a lot for any help!

Best Wishes,
Markus
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Installing service

Hi Markus,

Parameters can be passed to a service in two ways:
- by using the "Arguments" field in the Service Properties page (these parameters will be passed to the service when it is installed)
- by using the "Arguments" field in the Control Operation parameters page (these parameters will be passed to the service when it is started by the control operation

I'm afraid that Windows Installer does not support passing parameters to a service during an uninstall. However, you can use the Services page to install the service and custom actions to start and stop it. For example, you can try using the net start and net stop commands for a custom action that launches cmd.exe.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Installing service

MarkusStrobl wrote:A major requirement is to install a service with a commandline parameter and start it afterwards (and do the opposite when uninstalling).

The service is a standard C++ service written using Win32API and can be installed with a call to the exe itself:

Install:

myservice.exe -i

Uninstall:

myservice.exe -u
[...]
Also when using CustomActions i wasn't successful so far.
Hello Markus,

as far as I know when using custom actions it is important to run the custom action after the installation directory has been determined and after the files have been copied to it.

My first guess for which sequence to use upon installation would be "InstallExecuteSequence/InstallFinalize" (context menu on "InstallExecuteSequence": Show Standard Action/Before Finalization/InstallFinalize).

In the custom action I would try to get the APPDIR property to know the installation directory and then execute the binary. You will have to use an "Execution Condition" to ensure that it runs only at installation (possibly "NOT Installed").

The following is an example in Javascript, using working code snippets, but the arrangement below is untested:

Code: Select all

function installServer()
{
	var shell = new ActiveXObject("WScript.Shell");

	try
	{
		var APPDIR = Session.Property("APPDIR");

		// Remove trailing backslashes, if any
		if (APPDIR.substr(APPDIR.length - 1) == "\\")
		{
			APPDIR = APPDIR.substr(0, APPDIR.length - 1);
		}

		// Path to binary in double quotes, parameters following after space char
		var exec = "\"" + APPDIR + "\\binaryexe\" parameters_for_binary";

		//shell.Popup("exec: " + exec);
		shell.Run(exec, 0, true);
	}
	catch(e)
	{
		// The following code untested, but you get
		// the idea
		var msg =  "Exception    : " + e + "\r\n";
		msg = msg + "  name       : " + e.name + "\r\n";
		msg = msg + "  number     : " + e.number + "\r\n";
		msg = msg + "  message    : " + e.message + "\r\n";
		msg = msg + "  description: " + e.description + "\r\n";
		shell.Popup(msg);
	}
MarkusStrobl
Posts: 10
Joined: Wed Jul 09, 2008 7:32 am

Re: Installing service

Hi folks,

thanks a lot for your help.

In the end i solved the problem using "installed custom actions" for install/uninstall and "attached custom actions" with calls to "net.exe start" respectively "net.exe stop"

Best Wishes,

Markus

Return to “Common Problems”