MsiLocateComponentA function (msi.h)

The MsiLocateComponent function returns the full path to an installed component without a product code. This function attempts to determine the product using MsiGetProductCode, but is not guaranteed to find the correct product for the caller. MsiGetComponentPath should always be called when possible.


INSTALLSTATE MsiLocateComponentA(
  [in]      LPCSTR  szComponent,
  [out]     LPSTR   lpPathBuf,
  [in, out] LPDWORD pcchBuf


[in] szComponent

Specifies the component ID of the component to be located.

[out] lpPathBuf

Pointer to a variable that receives the path to the component. The variable includes the terminating null character.

[in, out] pcchBuf

Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpPathBuf parameter. On input, this is the full size of the buffer, including a space for a terminating null character. Upon success of the MsiLocateComponent function, the variable pointed to by pcchBuf contains the count of characters not including the terminating null character. If the size of the buffer passed in is too small, the function returns INSTALLSTATE_MOREDATA.

If lpPathBuf is null, pcchBuf can be null.

Return value

Value Meaning
The component being requested is disabled on the computer.
The component is not installed. See Remarks.
One of the function parameters is invalid.
The component is installed locally.
The buffer provided was too small.
The component is installed to run from source.
The component source is inaccessible.
The product code or component ID is unknown. See Remarks.


The MsiLocateComponent function might return INSTALLSTATE_ABSENT or INSTALL_STATE_UNKNOWN, for the following reasons:


    The application did not properly ensure that the feature was installed by calling MsiUseFeature and, if necessary, MsiConfigureFeature.


    The feature is not published. The application should have determined this earlier by calling MsiQueryFeatureState or MsiEnumFeatures. The application makes these calls while it initializes. An application should only use features that are known to be published. Since INSTALLSTATE_UNKNOWN should have been returned by MsiUseFeature as well, either MsiUseFeature was not called, or its return value was not properly checked.


The msi.h header defines MsiLocateComponent as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Requirement Value
Minimum supported client 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 or Windows XP. See the Windows Installer Run-Time Requirements for information about the minimum Windows service pack that is required by a Windows Installer version.
Target Platform Windows
Header msi.h
Library Msi.lib
DLL Msi.dll

See also

Component-Specific Functions