MsiSetFeatureState Function

Windows Installer

MsiSetFeatureState Function

The MsiSetFeatureState function sets a feature to a specified state.

Syntax

C++UINT MsiSetFeatureState(
  __in  MSIHANDLE hInstall,
  __in  LPCTSTR szFeature,
  __in  INSTALLSTATE iState
);

Parameters

hInstall [in]

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

szFeature [in]

Specifies the name of the feature.

iState [in]

Specifies the state to set. This parameter can be one of the following values.

Value Meaning
INSTALLSTATE_ABSENT

The feature is not installed.

INSTALLSTATE_LOCAL

The feature is installed on the local drive.

INSTALLSTATE_SOURCE

The feature is run from the source, CD, or network.

INSTALLSTATE_ADVERTISED

The feature is advertised.

 

Return Value

The MsiSetFeatureState function returns the following values:

ERROR_FUNCTION_FAILED

The function failed.

ERROR_INVALID_HANDLE

An invalid or inactive handle was supplied.

ERROR_INVALID_PARAMETER

One of the parameters was invalid.

ERROR_SUCCESS

The function succeeded.

ERROR_UNKNOWN_FEATURE

An unknown feature was requested.

Remarks

The MsiSetFeatureState function requests a change in the select state of a feature in the Feature table and its children. In turn, the action state of all the components linked to the changed feature records are also updated appropriately, based on the new feature select state.

The MsiSetInstallLevel function must be called before calling MsiSetFeatureState.

When MsiSetFeatureState is called, the installer attempts to set the action state of each component tied to the specified feature to the specified state. However, there are common situations when the request cannot be fully implemented. For example, if a feature is tied to two components, component A and component B, through the FeatureComponents table, and component A has the msidbComponentAttributesLocalOnly attribute and component B has the msidbComponentAttributesSourceOnly attribute. In this case, if MsiSetFeatureState is called with a requested state of either INSTALLSTATE_LOCAL or INSTALLSTATE_SOURCE, the request cannot be fully implemented for both components. In this case, both components are turned ON, with component A set to Local and component B set to Source.

If more than one feature is linked to a single component (a common scenario), the final action state of that component is determined as follows:

  • If at least one feature requires the component to be installed locally, the feature is installed with a state of local.
  • If at least one feature requires the component to be run from the source, the feature is installed with a state of source.
  • If at least one feature requires the removal of the component, the action state is absent.

See Calling Database Functions from Programs.

If the function fails, you can obtain extended error information by using MsiGetLastErrorRecord.

Requirements

VersionWindows 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
HeaderMsiquery.h
LibraryMsi.lib
DLLMsi.dll
Unicode and ANSI namesMsiSetFeatureStateW (Unicode) and MsiSetFeatureStateA (ANSI)

See Also

Installer Selection Functions

Send comments about this topic to Microsoft

Build date: 8/13/2009

© 2009 Microsoft Corporation. All rights reserved.