deb
Posts: 9
Joined: Fri Jan 06, 2006 8:07 am

How to install a helper app before installation the main app

Hi

I want to install a driver before installing my application. This driver installation is done using an command line exe file and the exe file needs 4 other files to be in the same directory as itself. I do not want these files to be installed in the Application Target Directory.

If the driver installation fails - I donot want to go ahead with the installation. On failure I want to display my own message rather than a MSI failure message.

So - it can be called a prerequisite.

If the installation has been successfull and later the user uninstalls the application, I want to run a uninstallation exe for the driver uninstallation. This uninstaller command line exe does not need any other files in the same directory. I donot want this uninstaller exe to be installed in the Application Target directory too.

Can you help me out with the steps ?

I tried with several options but I do not have the correct solution yet.
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

The VBScript that will execute the helper application is presented below:

Code: Select all

Dim HelperPath, HelperApp
Dim pos, args, strCmd, ret

' Retrieve the path of the helper program
HelperApp = Session.Property("CustomActionData")
' MsgBox HelperApp

Set WshShell = CreateObject("WScript.Shell")

' Extract the path of the helper app
pos = InStrRev(HelperApp, "\", Len(HelperApp))
MsgBox Len(HelperApp) & " " & pos
HelperPath = Left(HelperApp, pos)
' MsgBox HelperPath

' Set the current directory
WshShell.CurrentDirectory = HelperPath

' The arguments that are passed to the helper program
args = "file1.ini" & " " & "file2.dll"

' Invoke the program: we must use quotes arround the whole command
strCmd = chr(34) & HelperApp & chr(34) & " " & args
' MsgBox strCmd

' Run the command
ret = WshShell.Run(strCmd, 1, true)
' MsgBox ret

' Check the return code
If ret <> 0 Then
    MsgBox "Error !"
    Quit ret
End If

' TODO: delete the helper app and related files
This script retrieves the path of the helper application, sets the current directory with this path and then executes the helper program with 2 command line arguments (2 files that must exist in the same folder as itself).

The return code is checked and an error is displayed if necessary. Note that you can not stop the MSI failure message from appearing. However, this message can be changed by modifying the appropriate dictionary files.

You should also add code that deletes the helper program an the related files.


These are the steps you should follow:
1. In the Custom Actions page, make sure that the "InstallFiles" item appears in the tree control.

2. Add a "Property Set with Formatted" Custom Action after the "InstallFiles" stage. Set the Property Name to "HelperPath", then use the "Edit" button at the right of the "Formatted Text" field to select the helper program from your package.

3. Add a "New Attached Custom Action" after the "InstallFiles" stage and select the file containing the above script.
- Make sure that the name of this Custom Action (the item name in the tree control) is set to "HelperPath" (the name of the property set by the above Custom Action).
- Make sure that the Function Name field is empty.
- Set the Execution Option to "Deferred".

4. For both of the above Custom Actions, set the Execution Condition to: (Not Installed).

5. The program that performs the removal of your driver components can be added as an Attached Custom Action with the Execution Condition set to: REMOVE = "ALL"

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
Mihai
Posts: 38
Joined: Wed Mar 23, 2005 12:19 pm

Hi,

I would suggest the following approach:
- Create a MSI package for your driver that will install and uninstall it.
- Add the MSI driver package as a forced prerequisite to you application package. The removal of your application will also trigger the driver uninstallation.

Here is how can you achieve that (some steps are explained for the new Advanced Installer 3.6 so it is recommended to update your version if necessary):

1. The Driver MSI package must contain:
a) the EXE file and the other 4 files it depends on
b) for install: a Deferred Custom Action that will launch the EXE with the appropriate command line and also with the current directory set to the directory of the EXE.
c) for uninstall: an Property Source Custom Action. This must be scheduled after the property has been set.
d) a registry value to be used as search criteria in your other package (the package containing your application). The "Data" of that registry value must be "[PoductVersion]" (without quotes).
e) Basic UI (optional).
f) and eventually a Custom Action to delete the files that are not
needed any more.

Here is how you can implement step b).

The install CA must be under "InstallFiles" Standard Action so add this
item to the sequence tree from the left panel of the Custom Actions
page.

To have a "deferred EXE with working dir and command line" action you must:
A. Add a "Property Set with Formatted" with:
- Property Name: HelperPath
- Formatted Text: [#Helper.exe] (press the Edit button, then the File button to select the EXE file from your package)
- Execution Options: Immediate execution.
NOTE: you can also use this property in the Property Source CA that will remove the driver.

B. Save the VBScript provided in the previous post to a file and add it as an Attached Custom Action.
You have to:
- rename this custom action (select the tree item and press F2) to
"HelperPath" (note that this is the property that you set above);
- use an empty Function Name;
- use as Execute Option: Deferred;
- use as Execution Condition: Not Installed


2. In the package that installs your application, you have to:
A. add a new prerequisite (from the Media page > Prerequisites > New
button). You must also use:
- the "Force installation of the prerequisite" option from the "Install Conditions" tab.
- Search Criteria: Registry Value
- Registry Value: "HK??\Soft..." (if you have the Driver package
installed you can easily use the "..." button and select the registry value)

B. add an uninstall CA that will remove the driver.
- use the Wizard > Search... menu item to create a new Search for the
"msiexec.exe" file. You can leave all other fields unchanged because the
msiexec should be found in the [SystemFolder].
- add a Property Source custom action and use:
- Property Name: RESULT_PROPERTY
- Command Line: /x ProductCodeOfTheDriverMSI /qn
You can find the product code of the Driver's package by opening the
AIP file with a text editor. On the 10'th row or something like that you
will find the ProductCode property having as value something like:
10??:{?...?-?...?-?...?-?...?-?...?}. Well the ProductCode of the
Driver's package is the "{?...?-?...?-?...?-?...?-?...?}" section.
Mihai Udrea
Advenced Installer Team
deb
Posts: 9
Joined: Fri Jan 06, 2006 8:07 am

Thanks

Hey

Thanks for all that help - to both of you. It is great getting the feedback from you guys - opens up a totally different world on Advanced Installer.

I did as you said - everything works fine - except the last part of unintalling with /x ProductCode /qn . It is not working.

I added a Property Source Custom Action within Uninstall in the Install Sequence Tree View, with Property name RESULT_PROPERTY ( as created after searching for msiexec.exe in systemfolder) and Command Line as written below ( with the actual product code )

/x {CD85B4B5-4A3F-4697-B73D-DD35BAF1FAD5} /qn

But the uninstaller is not being invoked . Any thing which you find a problem in my approach ?

Please let me know
Thanks
Deb
deb
Posts: 9
Joined: Fri Jan 06, 2006 8:07 am

I know the reason why it is failing

The msiexec /x productcode aborts with the error that a msi instance is already running and another instance of the same application cannot be loaded at the same time.

What is the problem ? Anything with the Sequence or the Executing Option ?
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,

You are right.

You should move the "Property Source" Custom Action that uninstalls your prerequisite on the "InstallFinalize" stage and set its Execution Property to "Asynchronous execution, do not wait for return". I would also recommend not to use the "/qn" switch.

Regards,
Denis
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”