MsiInstallProduct function (Windows)

Switch View :
ScriptFree
MsiInstallProduct function

Applies to: desktop apps only

The MsiInstallProduct function installs or uninstalls a product.

Syntax

UINT MsiInstallProduct(
  __in  LPCTSTR szPackagePath,
  __in  LPCTSTR szCommandLine
);

Parameters

szPackagePath [in]

A null-terminated string that specifies the path to the location of the Windows Installer package. The string value can contain a URL (e.g. http://packageLocation/package/package.msi), a network path (e.g. \\packageLocation\package.msi), a file path (e.g. file://packageLocation/package.msi), or a local path (e.g. D:\packageLocation\package.msi).

szCommandLine [in]

A null-terminated string that specifies the command line property settings. This should be a list of the format Property=Setting Property=Setting. For more information, see About Properties.

To perform an administrative installation, include ACTION=ADMIN in szCommandLine. For more information, see the ACTION property.

Return value

ValueMeaning
ERROR_SUCCESS

The function completes successfully.

An error relating to an action

For more information, see Error Codes.

Initialization Error

An error that relates to initialization occurred.

 

For more information, see Displayed Error Messages.

Remarks

The MsiInstallProduct function displays the user interface with the current settings and log mode.

For more information, see REMOVE Property.

Requirements

Version

Windows Installer 5.0 on 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

MsiInstallProductW (Unicode) and MsiInstallProductA (ANSI)

See also

Displayed Error Messages
Error Codes
Initialization Error
Installation and Configuration Functions
Multiple-Package Installations

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Community Content

Martin Chapman
Convert MSI Error Code to Description String
I wanted to convert the MSI error code to a human readable string and didn't find anything good on the Internet so I thought I would share my solution.  The following code uses the error code from any MSI API function to get the error string from the resource dll associated with MSI.

// example code

// call your MSI API function ... MsiInstallProduct() in this case
DWORD result = MsiInstallProduct(installerFullPath, commandLine);
if (result != ERROR_SUCCESS)
{
    CString message;
    message.Format(_T("%s"), GetMessageFromMsiErrCode(result).GetBuffer());
    // .... do whatever with the error message
}

// function to get error message from msimsg.dll resource dll
CString GetMessageFromMsiErrCode(DWORD error)
{
CString message = _T("Unknown error");
HMODULE module = LoadLibraryEx(_T("msimsg.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE);
if (module == NULL) return message;
TCHAR buffer[8192] = _T("");
LoadString(module, error, buffer, sizeof(buffer) / sizeof(TCHAR));
FreeLibrary(module);
message = buffer;
return message;
}

Best regards,
Marty

JonK
If you want to uninstall something in code
and you can't rely on the end user having the original MSI to hand then use MsiConfigureProduct(productCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_ABSENT) instead.

Robert Flaming - MSFT
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.