Getting Started with InstallShield Automation and Perl

It’s true, even Windows users succumb to the allure of extensibility and readability of Perl.  Some even opt to use it to automate the build processes of their products and associated installers.

But, there’s a problem.  The InstallShield Help Library generally provides examples in the most ubiquitous Windows scripting language — VBScript.  The idea behind this is that working with COM Objects and Collections will be specific to the language in question, and that the core ideas behind the VBScript samples will apply to each in a very similar fashion.

While this indeed does hold to be true, it can be daunting if you are suddenly tasked with writing a script from scratch.  Below are some of the VBScript examples from the InstallShield Help, translated to Perl.

Using the ISWiProject Object

This example demonstrates how to open an InstallShield project file.

use Win32::OLE;
my $dev = Win32::OLE->new(“IswiAuto17.ISWiProject”);
$myproject = “C:InstallShield 2011 ProjectsMY 64 bit Project.ism”;
$dev->OpenProject($myproject);

Using the ISWiFeature Object

This example illustrates how to iterate through the root level features and components.

use Win32::OLE;
my $dev = Win32::OLE->new(“IswiAuto17.ISWiProject”);
$myproject = “C:InstallShield 2011 ProjectsMy Test Project.ism”;

$dev->OpenProject($myproject);
$strOutput = “”;
$myfeatures =  $dev->ISWiFeatures;

foreach my $feature (in $myfeatures)
{
$strOutput = $strOutput . “Feature: ” . $feature->Name . “n”;
$strOutput = $strOutput . “Components: “;
$mycomps = $feature->ISWiComponents;
foreach my $component (in $mycomps)
{
$strOutput = $strOutput . $component->Name . ” “;
}
$strOutput = $strOutput . “n”;
}
print STDOUT $strOutput;
$dev->CloseProject();

Using the ISWiComponent Object

This example illustrates how to get a specific feature from the ISWiFeatures collection, use it to set component properties, and then how to save the project.  As you can see, getting an item from a collection looks similar to a function call.

use Win32::OLE;

use constant {
rfsLocal => 0,
rfsSource => 1,
rfsOptional => 2,
};

my $dev = Win32::OLE->new(“IswiAuto17.ISWiProject”);
my $myproject = “C:InstallShield 2011 ProjectsMy Test Project.ism”;

$dev->OpenProject($myproject);
$feature = $dev->ISWiFeatures(“MyApplication”);

$mycomps = $feature->ISWiComponents;
foreach $component (in $mycomps)
{
$component->{‘RemoteInstallation’} = rfsSource;
}

$dev->SaveProject();
$dev->CloseProject();

Leave a Reply

Your email address will not be published. Required fields are marked *