Friday, June 18, 2010

Pascal scripting in InnoSetup

As part of a recent project, a new standalone component was developed which was to be bundled with an existing product. One of the related tasks involved the integration of the MSI installer for the new component with the installer for the existing product, which was created using InnoSetup - a free, open-source script-driven installation system.

Piggybacking the installer for the new component was straightforward, using the following instruction in the Run section of the InnoSetup script.
Filename: msiexec.exe;
Parameters: /i {tmp}\ProductXYZSetup.msi;
StatusMsg: Installing ProductXYZ...;
Flags: postinstall
The process of uninstalling the new component along with the main product (or giving the user the opportunity to uninstall the component) was a bit more complicated. InnoSetup supports Pascal scripting for carrying out custom actions before, during, or after the install process - for example, adding custom wizard pages or installing certain files depending on runtime conditions. The script below asks the user if they want to uninstall ProductXYZ, then checks the registry for the UninstallString entry which is associated with the product code for the standalone component.
[Code]
procedure UninstallComponent();
var
ProductCode: String;
RegKey: String;
UninstallString: String;
ResultCode: Integer;
begin
ProductCode := '{1234-XXXX-1234-XXXX}';
RegKey := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + ProductCode;

if RegQueryStringValue(HKEY_LOCAL_MACHINE, RegKey, 'UninstallString',
UninstallString) then
begin
MsgBox('Uninstalling ProductXYZ...', mbInformation, MB_OK);
Exec('>', UninstallString, '', SW_SHOW, ewNoWait, ResultCode);
end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall then begin
if MsgBox('Do you want to uninstall the Product XYZ?',
mbConfirmation, MB_YESNO) = IDYES
then
begin
UninstallComponent();
end;
end;
end;
Using this method it is possible to seamlessly install and uninstall multiple related applications, without any interaction from the user.

No comments:

Post a Comment