Modifying Min and Max Upgrade Version With VBScript

X

xJoey.t

I'm fairly new to msi and am trying to figure out how to change the
MinVersion and MaxVersions in the Upgrade Table using VBScript. I have
found a few examples but none of them seem to work. I would be using
the InstallShield Automation object but it has a bug when you try to
access an Upgrade table that has multiple entries. I found a Perl
script on the Installshield website and tried to convert it to VBS but
it's failing. This is the Perl I'm converting:

#!perl -w

use WIN32::OLE;

my $productVersion = "1.10.0015";
my $ismfile = "C:\\MyApp\\MyApp.ism";

#Need to open the project file in binary format for Windows Installer
to recognize it as a database.
$m_ISWiProject = Win32::OLE->CreateObject("SAAuto1050.ISWiProject") or
print "Cannot start ISIDE.\n";
$m_ISWiProject->OpenProject($ismfile);
$m_ISWiProject->{'UseXMLProjectFormat'} = 0;
$m_ISWiProject->SaveProject();
$m_ISWiProject->CloseProject();

#Using Windows Installer API to update the upgrade table
my $m_WIObject =
Win32::OLE->CreateObject("WindowsInstaller.Installer") or print
"Cannot create Windows installer object.\n";
# Open database in transacted mode
my $db = $m_WIObject->Opendatabase($ismfile,1);

my $newproducts_SQLstring=" SELECT * FROM Upgrade WHERE
ActionProperty='NEWPRODUCTS' ";
my $newView = $db->OpenView($newproducts_SQLstring);
$newView->Execute;

# Fetch the one and only record containing NEWPRODUCTS
$newRecord = $newView->Fetch;

#VersionMin is the 2nd field in the StringData property string. If you
would like to update VersionMax: that is the 3rd field in the
StringData property string.
#Set VersionMin to current ProductVersion
if (defined $newRecord){
$newRecord->SetProperty('StringData',2,$productVersion);

#Modify the view in mode 4 (MSIMODIFY_REPLACE).
#This mode is required because you need to update primary keys in the
table
$newView->Modify(4,$newRecord);
}
$newView->Close;
$db->Commit;
Don´t bother trying to use any fancy UPDATE sql statements with the
Upgrade table, it won´t work (VersionMin and VersionMax being primary
keys...).

When I run this it fails at the line:

$newRecord->SetProperty('StringData',2,$productVersion);

It appears that SetProperty is not a valid method here!

I hope someone can help, this is making me crazy!!
 
M

mgama

As you noted there are several primary keys in the Upgrade table, which
makes updating those tricky using SQL. I'm not much of a VBS buy, but I've
succeeded in taking the existing VBS sample scripts in the PlatformSDK
(Windows Installer feature) and tweaking them to meet my needs.

You could use wirunsql.vbs as a starting point. I personally would read in
the entire row, store each of the values, delete that row, modify the values
(VersionMin or VersionMax in your case),and then insert the new data to the
table. It may not be elegant, but I think I would have better luck tracking
down problems this way. I haven't tried doing the MSIMODIFY_REPLACE which
you have in the code below.
 
S

Sean

I do this by feeding parameters to wirunsql.vbs; delete the Upgrade table
then insert the new rows (with the new version values)...upon every build.
I would suggest adding this to your automated build functionality.

If you need an example, I will post one, soon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top