Microsoft Windows Installer

Commands for accessing Microsoft Windows Installer


package require twapi_msi


Incompatibility note: The Windows Installer support in TWAPI 4.3 replaces the experimental module in previous versions of TWAPI.

Support for Windows Installer functionality is provided through the general COM interface provided by the twapi_com module. For details about Windows Installer components, properties and methods, consult the Windows Installer documentation. These can then be invoked using the twapi_com interfaces. The example below, illustrating how to execute a SQL script against a Windows Installer package, demonstrates such usage.

First we get hold of the Windows Installer component itself.

% package require twapi_msi
% set msi [comobj WindowsInstaller.Installer]

Then we have it open our sample Windows Installer MSI package.

% set db [$msi OpenDatabase ../tests/sample.msi 0]

Now a crucial step is that because the Windows Installer components do not support runtime type information interfaces, we have to explicitly declare the type of the component as described in the twapi_com documentation.

% windowsinstaller::declare Database $db

We can now invoke methods on the object, in this case creating a View based on a SQL query. (Database, View etc. are all described in the Windows Installer documentation.)

% set view [$db OpenView "select Title, Description from Feature where Feature='Complete'"]

Again, we have to declare the type of the returned object. This time, we use an alternative method for the purpose.

% $view -instanceof windowsinstaller::View

We can now run the SQL query and fetch the results.

% $view Execute
% set rec [$view Fetch]

Further proceeding in a similar fashion we print the results.

% $rec -instanceof windowsinstaller::Record
% $rec StringData 1
Windows Inspection Tool Set
% $rec -destroy;                # All COM objects have to be destroyed
% set rec [$view Fetch];  # Fetch the next
::twapi::comobj_null;           # No more

Finally, we have to clean up after ourselves as required by COM.

% $view -destroy
% $db -destroy
% $msi -destroy


Copyright © 2007-2018 Ashok P. Nadkarni

Tcl Windows API 4.3.5