InstallShield Tip: Accessing the MSI Database at Run Time



Similar documents
Microsoft Access Creating Filters and Tables

Microsoft Access 2007

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Architecting the Future of Big Data

Toad for Oracle 8.6 SQL Tuning

IT Administrator Guide for Mass Deployment of WebEx Productivity Tools. Installation Guide for Administrators

Microsoft Office Access 2007 which I refer to as Access throughout this book

Architecting the Future of Big Data

Knowledgebase Article

AdminStudio Release Notes. 16 July Introduction New Features... 6

!"#"$%&'(()!!!"#$%&'())*"&+%

Netezza Workbench Documentation

Silect Software s MP Author

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Create a New Database in Access 2010

Vendor: Crystal Decisions Product: Crystal Reports and Crystal Enterprise

Product: DQ Order Manager Release Notes

v4.8 Getting Started Guide: Using SpatialWare with MapInfo Professional for Microsoft SQL Server

Abstract. For notes detailing the changes in each release, see the MySQL for Excel Release Notes. For legal information, see the Legal Notices.

DbSchema Tutorial with Introduction in SQL Databases

Contents. Introduction. Chapter 1 Some Hot Tips to Get You Started. Chapter 2 Tips on Working with Strings and Arrays..

Das AdminStudio beinhaltet eine ganze Reihe von Tools zum Thema Anwendungspaketierung- und Virtualisierung, die wir ihnen nachfolgend zeigen wollen:

PTC Integrity Eclipse and IBM Rational Development Platform Guide

Search help. More on Office.com: images templates

IT Administrator Guide for Mass Deployment of WebEx Productivity Tools

Part II Acrobat 8 Professional

Creating Database Tables in Microsoft SQL Server

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

Using SQL Queries in Crystal Reports

Office of History. Using Code ZH Document Management System

Desktop, Web and Mobile Testing Tutorials

Sage ERP Accpac 6.0A. System Manager I Customizing Reports and Forms

Access Queries (Office 2003)

Call Recorder Oygo Manual. Version

Creating and Using Databases with Microsoft Access

PageR Enterprise Monitored Objects - AS/400-5

Microsoft Access 3: Understanding and Creating Queries

Performance Management Platform

Unit 10: Microsoft Access Queries

StreamServe Persuasion SP5 Document Broker Plus

Evaluator s Guide. PC-Duo Enterprise HelpDesk v5.0. Copyright 2006 Vector Networks Ltd and MetaQuest Software Inc. All rights reserved.

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

Microsoft Dynamics CRM 4.0 User s Guide

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

Coveo Platform 7.0. Microsoft Dynamics CRM Connector Guide

Web Development using PHP (WD_PHP) Duration 1.5 months

Special Edition for FastTrack Software

Novell ZENworks 10 Configuration Management SP3

Technical Reference: Deploying the SofTrack MSI Installer

Release Document Version: User Guide: SAP BusinessObjects Analysis, edition for Microsoft Office

Reflection DBR USER GUIDE. Reflection DBR User Guide. 995 Old Eagle School Road Suite 315 Wayne, PA USA

Customizing MISys Manufacturing Reports Using ADO-XML 6/3/2013

SourceAnywhere Service Configurator can be launched from Start -> All Programs -> Dynamsoft SourceAnywhere Server.

LESSON 4 - FILE MANAGEMENT

FileMaker Server 12. FileMaker Server Help

Using the Query Analyzer

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Monitoring Server File Integrity With CloudPassage Halo

Setting Up ALERE with Client/Server Data

Librarian. Integrating Secure Workflow and Revision Control into Your Production Environment WHITE PAPER

TECHNICAL DOCUMENTATION SPECOPS DEPLOY / APP 4.7 DOCUMENTATION

Product Navigator User Guide

Introduction to Microsoft Access 2003

Improving Your Relationship with SAS Enterprise Guide

Easy way to manage add-in deployment

Oracle Database 12c: Introduction to SQL Ed 1.1

Making the Most of Files & Folders. Schoolwires Centricity2

You must have at least Editor access to your own mail database to run archiving.

Architecting the Future of Big Data

Master Data Services. SQL Server 2012 Books Online

RIT Installation Instructions

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Here are three definitions that will help when reading the report chapters:

Qlik REST Connector Installation and User Guide

Xcode Project Management Guide. (Legacy)

SPHOL207: Database Snapshots with SharePoint 2013

XEROX, The Document Company, the stylized X, and the identifying product names and numbers herein are trademarks of XEROX CORPORATION.

Documentum Content Distribution Services TM Administration Guide

Oracle Database: SQL and PL/SQL Fundamentals

SnapLogic Salesforce Snap Reference

Tutorial 3. Maintaining and Querying a Database

Microsoft Office 2010

Microsoft Office Access 2007 Basics

Debugging Java Applications

Authoring for System Center 2012 Operations Manager

AdminStudio Installation Guide. Version 2013

XMap 7 Administration Guide. Last updated on 12/13/2009

Microsoft Visual Studio Integration Guide

EMC SourceOne for Microsoft SharePoint Storage Management Version 7.1

WS_FTP Professional 12

StreamServe Persuasion SP5 Ad Hoc Correspondence and Correspondence Reviewer

Chapter 5. Microsoft Access

Enterprise Product Integration

Transcription:

InstallShield Tip: Accessing the MSI Database at Run Time Robert Dickau Senior Techincal Trainer Flexera Software Abstract In some cases, it can be useful for a running installation to access the tables of the running MSI database. This article provides an overview of accessing and temporarily modifying MSI database tables at run time using custom actions. Accessing Database Tables In VBScript, the Session object provides a Database property, which represents the running MSI database. (In InstallScript and C, the API function MsiGetActiveDatabase returns the same information.) In a custom action, you can execute SQL queries on the running database. Performing SQL Queries The steps to access an MSI database at run time are the following. 1. Open a view to the running database, using a SQL SELECT statement. 2. Execute the view. 3. Fetch the records returned by the view, and extract data from the desired fields. 4. Close the view. Step 1 involves creating a SQL SELECT statement. The general form of a SELECT statement is the following. SELECT Fields FROM Tables For example, to select all the fields from the FeatureComponents table, the query would appear as follows, using the asterisk (*) to indicate all the fields. SELECT * FROM `FeatureComponents` To avoid conflicts with SQL keywords, it is recommended you place field and table names in backquotes (`). Another way to perform the same query is to explicitly identify the desired field names: SELECT `Feature_`,`Component_` FROM `FeatureComponents` You can additionally narrow a SELECT statement using a WHERE clause followed by a 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 1 of 7

comparison between a field value and a constant string, or between two field values. For example: SELECT * FROM `Control` WHERE `Dialog_`='SetupCompleteSuccess' Constants used in a comparison should be enclosed in single quotes ('). The MSI Help Library page "SQL Syntax" describes more keywords that can be used in queries on an MSI database. Note that MSI supports only a subset of "full" SQL syntax: for example, the LIKE and LEN operators are not supported. What a SQL query returns is a set a records that match the query. A record, or row, is an indexed set of fields, and your custom action code can use the StringData and IntegerData properties of a Record object to retrieve the desired data. For example, suppose a custom action performs the following query: SELECT `Feature`,`Level` FROM `Feature` Each record returned will contain two fields: the Feature field, which contains the string identifier for a feature, and the numeric Install Level value for the feature. In code (assuming the record object is stored in a variable called rec), you would use the following to refer to the first (string) field of a fetched record: rec.stringdata(1) ' indexing starts with 1 And you would use the following to refer to the second (integer) field of a fetched record: rec.integerdata(2) To determine the type of data used by a field, you can view the desired table's MSI Help Library page. An easy way to open the help page for a specific table is to select the table in InstallShield's Direct Editor view and press F1. Example: Querying the Property Table For example, the following code fetches the ProductName record from the Property table, and then displays the ProductName value. (This example is simply for illustration; in this particular case, the expression Session.Property("ProductName") returns the same information.) Const IDOK = 1 Function ReadProductName( ) ' open and execute the view Set oview = Database.OpenView("SELECT `Value` FROM `Property` WHERE ` Property`='ProductName'") oview.execute ' fetch the one and only ProductName record Set orecord = oview.fetch 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 2 of 7

' display the string data from the fetched record MsgBox "ProductName = " & orecord.stringdata(1) ' clean up oview.close ' return success to MSI ReadProductName = IDOK End Function To use the previous code in a custom action, place the code in a VBScript source file called (for example) ReadProductName.vbs. Next, in the Custom Actions view of the IDE, right-click the Custom Actions icon and select New VBScript > Stored in the Binary table, renaming the action icon to (say) callreadproductname. In the property list for the callreadproductname action, specify the following settings: VBScript Filename: <readprodnamesrc>\readproductname.vbs (browse for ReadProductName.vbs) Script Function: ReadProductName (the function name in the VBS file) Install UI Sequence: After SetupInitialization After building and running the product, the custom action displays a message box as follows. 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 3 of 7

As with accessing MSI properties, accessing the running MSI database is valid only for custom actions scheduled for immediate execution. For an example of accessing custom tables at run time, see the MSI Help Library section "How do I use a custom action to create user accounts on the local computer?", along with the corresponding code from the MSI Platform SDK. Modifying Database Tables Windows Installer also supports adding temporary records to a running MSI database. Perhaps the most common use for adding temporary records to a running database is to populate user-interface elements with data not available until run time. (Of course, this technique is appropriate only for Basic MSI projects; for InstallScript MSI projects, you populate and manipulate user-interface controls using the InstallScript functions CtrlSetText, CtrlSetList, CtrlSetCurSel, and so forth.) For example, suppose you want to populate a ListBox control with the current values of every property listed in the Property table. To begin, you might add a ListBox control to the ReadyToInstall dialog box (using InstallShield's Dialog Editor), associating the control with the property LISTBOXPROP. (If desired, you can set the ListBox properties Sorted and Sunken to True.) Instead of populating the Items property of the ListBox control at design time, however, you will populate its items at run time by inserting temporary records into the ListBox table. You might then place the following code in a source file called PropDisplay.vbs. Const msiviewmodifyinserttemporary = 7 Const IDOK = 1 Function PropDisplay( ) ' open and execute a view to the ListBox table Set viewlist = Database.OpenView("SELECT * FROM `ListBox` WH ERE `Property`='LISTBOXPROP'") viewlist.execute ' open and execute a view to the Property table Set viewprop = Database.OpenView("SELECT * FROM `Property`") viewprop.execute Set recprop = viewprop.fetch r = 0 While Not (recprop Is Nothing) ' ListBox record fields are Property, Order, Value, Text Set reclist = Installer.CreateRecord(4) r = r + 1 reclist.stringdata(1) = "LISTBOXPROP" reclist.integerdata(2) = r reclist.stringdata(3) = recprop.stringdata(1) 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 4 of 7

reclist.stringdata(4) = recprop.stringdata(1) & "=" & Session.Property(recprop.StringData(1)) ' insert the temporary ListBox record viewlist.modify msiviewmodifyinserttemporary, reclist ' fetch the next Property record Set recprop = viewprop.fetch Wend ' clean up viewprop.close: viewlist.close ' return success to MSI PropDisplay = IDOK End Function Note the use of the Modify method of the View object (with the insert-temporary constant), which modifies or adds a database record. In the Custom Actions view, as before, right-click the Custom Actions icon and select New VBScript > Stored in the Binary table, renaming the action to callpropdisplay, browsing for PropDisplay.vbs in the VBScript Filename field, and specifying PropDisplay in the Script Function field. You can then either schedule the action early in the User Interface sequence, or using a DoAction control event on the Next button of (say) the SetupType dialog box. After building and running the MSI package, the ReadyToInstall dialog box showing the temporary records might appear as follows. 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 5 of 7

(You will generally want to ensure that code inserting temporary records runs only once: the previous code will generate a run-time error if it is run twice, because calling the Modify method with the insert-temporary flag fails if a record with a given primary key already exists. An alternative is to delete any temporary records that exist, using code similar to the following at the beginning of the PropDisplay function: Set viewlist = Database.OpenView("SELECT * FROM `ListBox` WH ERE `Property`='LISTBOXPROP'") viewlist.execute Set reclist = viewlist.fetch ' delete any existing LISTBOXPROP records While Not (reclist Is Nothing) viewlist.modify 6, reclist ' 6 = delete Set reclist = viewlist.fetch Wend viewlist.close This block of code prevents clashes with existing ListBox/LISTBOXPROP records, therefore preventing errors if the user clicks the Back button and then revisits the ReadyToInstall dialog box.) 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 6 of 7

As with ListBox controls with items populated at design time, the user's selection in the ListBox, if any, will be stored in the LISTBOXPROP (in this example) property. As always, only the value of a public property will be preserved when execution switches from the User Interface sequence to the Execute sequence. You can use similar code to populate a ListBox control with a list of mapped network drives, user accounts, directory names, or other data that can be discovered only while an installation is running on a particular target system. For a similar example using C (easily converted to InstallScript), see InstallShield Knowledge Base article Q103295 at http://kb.flexerasoftware.com. When working with MSI database access at run time, you should keep the following in mind: Windows Installer does not support permanently modifying a running MSI database: changes you make at run time will not be stored in the MSI database cached on the user's system. Moreover, Windows Installer reloads the MSI database when execution switches from the User Interface sequence to the Execute sequence. Therefore, temporary modifications to a database made in the User Interface sequence will be lost when execution switches to the Execute sequence. As mentioned earlier, custom actions can access the running database only during immediate execution, and not deferred execution. Further Directions Other uses for accessing MSI database tables include: Modifying an MSI database (or ISM project file) as part of a post-build step, or to automate changes not exposed by the ISWiAutomation interface. For an example, see the previous newsletter article "Using MSI Automation to Modify an InstallShield Project". Creating custom ICE rules. For a discussion of custom ICE rules, see Appendix D of Administrator's Introduction to Application Repackaging and Software Deployment using Windows Installer. 2010 Flexera Software, Inc. and/or InstallShield Co. Inc. All rights reserved. 7 of 7 IS_MSIAccess_TT_Aug08