MsiOpenPackage function

Expand
1 out of 3 rated this helpful - Rate this topic

MsiOpenPackage function

Applies to: desktop apps only

The MsiOpenPackage function opens a package to use with the functions that access the product database. The MsiCloseHandle function must be called with the handle when the handle is not needed.

Note  Initialize COM on the same thread before calling the MsiOpenPackage, MsiOpenPackageEx, or MsiOpenProduct function.

Syntax

UINT MsiOpenPackage(
  __in   LPCTSTR szPackagePath,
  __out  MSIHANDLE *hProduct
);

Parameters

szPackagePath [in]

The path to the package.

hProduct [out]

A pointer to a variable that receives the product handle.

Return value

ValueMeaning
ERROR_BAD_CONFIGURATION

The configuration information is corrupt.

ERROR_INSTALL_FAILURE

The product could not be opened.

ERROR_INSTALL_REMOTE_PROHIBITED

Windows Installer does not permit installation from a remote desktop connection.

ERROR_INVALID_PARAMETER

An invalid parameter is passed to the function.

ERROR_SUCCESS

The function completes successfully.

 

If this function fails, it may return a system error code. For more information, see System Error Codes.

Remarks

MsiOpenPackage can accept an opened database handle in the form "#nnnn", where nnnn is the database handle in string form, i.e. #123, instead of a path to the package. This is intended for development tasks such as running validation actions, or for use with database management tools.

Requirements

Version

Windows Installer 5.0 on Windows Server 2012, Windows 8, Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003, Windows XP, and Windows 2000. See the Windows Installer Run-Time Requirements for information about the minimum Windows service pack that is required by a Windows Installer version.

Header

Msi.h

Library

Msi.lib

DLL

Msi.dll

Unicode and ANSI names

MsiOpenPackageW (Unicode) and MsiOpenPackageA (ANSI)

See also

Product Query Functions

 

 

Build date: 5/5/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
More requirements for MsiOpenPackage
For an MSI to be opened by MsiOpenPackage, it must have a Summary table with the following fields:

{ PID_TITLE, VT_LPSTR, L"MSI Shim Database" },
{ PID_SUBJECT, VT_LPSTR, L"MSI Shim Database" },
{ PID_AUTHOR, VT_LPSTR, L"Test" },
{ PID_TEMPLATE, VT_LPSTR, ";1033" },
{ PID_REVNUMBER, VT_LPSTR, "{00869AA3-A32E-4398-89B2-5C5DC7328C7C}" },
{ PID_PAGECOUNT, VT_I4, 100 },
{ PID_WORDCOUNT, VT_I4, 100 },

In addition, the behavior of MsiOpenPackage has changed on Windows 7 and requires a Property table with a ProductCode property. Otherwise you'll get 0x80070645: This action is only valid for products that are currently installed.

CREATE TABLE `Property` (`Property` CHAR(72) NOT NULL, `Value` CHAR(0) NOT NULL LOCALIZABLE PRIMARY KEY `Property`)
INSERT INTO `Property` (`Property`, `Value`) VALUES ('ProductCode', '{07F7FB1B-992E-4a2d-805C-C803C98CFC42}')

http://msiext.codeplex.com has working C++ code for all this stuff.
2/10/2010
additional information

You need to call CoInitializeEx on the same thread before calling this function. You also must have the msi actually installed for this to work. Otherwise, use MsiOpenPackageEx.

Hex Values for Win32 error codes Published as part of Open Protocol Specifications

As a part of the Open Protocol Specifications, the hex values for Win32 error codes can now be found at http://msdn2.microsoft.com/en-us/library/cc231199.aspx.