Author

I am Joannes Vermorel, founder at Lokad. I am also an engineer from the Corps des Mines who initially graduated from the ENS.

I have been passionate about computer science, software matters and data mining for almost two decades. (RSS - ATOM)

Meta
« Minimal back-office for your eBusiness | Main | Homeworks going freelance »
Sunday
Apr152007

Improved "Run external program" through environment variables

Dynacom is a Canadian accounting software that provides an add-on development framework named Synergy. We have started to work on an integration of the Lokad Desktop Sales Forecasting with Dynacom. This post might interest developers who want to integrate together several windows applications (we are considering Dynacom here, but the process would be quite similar for another application).

Basically, Dynacom provides build-in custom action Run external program; yet, this action has a huge drawback: it requires either your application to be part of the PATH on the client machine or it requires to provide an absolute file location (which is likely to vary from one machine to another). A lazy approach would consist in letting the user manually enter the application path; but this approach is likely to be a huge pain for the average user who may not be familiar with the location and the content of the Program Files directory.

Thus I have decided to create a Windows Environment Variable dedicated to Lokad Desktop Sales Forecasting. In the Windows Installer XML packaging script, I have added the following lines

<Environment Id="LokadDesktopPathVariable"
Action="set"
Name="LOKAD_DESKTOP_PATH"
Part="all"
Permanent="no"
System="no"
Value="[INSTALLLOCATION]" />

to get a new LOKAD_DESKTOP_PATH environment variable to be created at install-time (see Sourceforge for the full WiX script). Note that [INSTALLLOCATION] is a variable name; it might be different in your WiX script.

Then, in Dynacom, we retrieve the content of the LOKAD_DESKTOP_PATH environment variable though an Execute script action. The following VB-Script code illustrates how it is done.

Sub Main()
Set wshShell = CreateObject("WScript.Shell")
lokadPath = wshShell.ExpandEnvironmentStrings("%LOKAD_DESKTOP_PATH%")
lokadPath = lokadPath & "Lokad.Windows.SalesForecasting.exe"

' HACK: triple-quotes are actually needed to support path with spaces.
' http://weblogs.asp.net/steveschofield/archive/2004/03/14/89240.aspx
wshShell.Run """" & lokadPath & """"
End Sub

At the end, the Dynacom user will get an integration that is both straightforward and robust.