MsiEnumComponentCostsA function

The MsiEnumComponentCosts function enumerates the disk-space per drive required to install a component. This information is needed to display the disk-space cost required for all drives in the user interface. The returned disk-space costs are expressed in multiples of 512 bytes.

MsiEnumComponentCosts should only be run after the installer has completed file costing and after the CostFinalize action. For more information, see File Costing.


UINT MsiEnumComponentCostsA(
  MSIHANDLE    hInstall,
  LPCSTR       szComponent,
  DWORD        dwIndex,
  LPSTR        szDriveBuf,
  LPDWORD      pcchDriveBuf,
  LPINT        piCost,
  LPINT        piTempCost



Handle to the installation provided to a DLL custom action or obtained through MsiOpenPackage, MsiOpenPackageEx, or MsiOpenProduct.


A null-terminated string specifying the component's name as it is listed in the Component column of the Component table. This parameter can be null. If szComponent is null or an empty string, MsiEnumComponentCosts enumerates the total disk-space per drive used during the installation. In this case, iState is ignored. The costs of the installer include those costs for caching the database in the secure folder as well as the cost to create the installation script. Note that the total disk-space used during the installation may be larger than the space used after the component is installed.


0-based index for drives. This parameter should be zero for the first call to the MsiEnumComponentCosts function and then incremented for subsequent calls.


Requested component state to be enumerated. If szComponent is passed as Null or an empty string, the installer ignores the iState parameter.


Buffer that holds the drive name including the null terminator. This is an empty string in case of an error.


Pointer to a variable that specifies the size, in TCHARs, of the buffer pointed to by the lpDriveBuf parameter. This size should include the terminating null character. If the buffer provided is too small, the variable pointed to by pcchDriveBuf contains the count of characters not including the null terminator.


Cost of the component per drive expressed in multiples of 512 bytes. This value is 0 if an error has occurred. The value returned in piCost is final disk-space used by the component after installation. If szComponent is passed as Null or an empty string, the installer sets the value at piCost to 0.


The component cost per drive for the duration of the installation, or 0 if an error occurred. The value in *piTempCost represents the temporary space requirements for the duration of the installation. This temporary space requirement is space needed only for the duration of the installation. This does not affect the final disk space requirement.

Return Value

Return Value Meaning
The configuration data is corrupt.
An invalid parameter was passed to the function.
There are no more drives to return.
A value was enumerated.
The component is missing.
Costing is not complete.
Buffer not large enough for the drive name.
The supplied handle is invalid or inactive.


The recommended method for enumerating the disk-space costs per drive is as follows. Start with the dwIndex set to 0 and increment it by one after each call. Continue the enumeration as long as MsiEnumComponentCosts returns ERROR_SUCCESS.

MsiEnumComponentCosts may be called from custom actions.

The total final disk cost for the installation is the sum of the costs of all components plus the cost of the Windows Installer (szComponent = null).


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
Target Platform Windows
Header msiquery.h
Library Msi.lib
DLL Msi.dll