PDA

View Full Version : Making a feature to required at runtime



huntant
04-08-2002, 02:08 PM
Is there a way to set the required property for a feature based on certain conditions?



Thanks,
Anthony

RobertDickau
04-09-2002, 02:44 PM
Two options:

Create two nearly identical features, one required and one not, and conditionally show the desired one; or modify the in-memory Feature table, using a custom action.

Something like the following in a DLL, perhaps:


#pragma comment(lib, "msi.lib")

#include <windows.h>
#include <msi.h>
#include <msiquery.h>

UINT __stdcall MakeFeatureRequired(MSIHANDLE hInstall)
{
PMSIHANDLE hView = NULL;
PMSIHANDLE hRecord = NULL;

PMSIHANDLE hDB = MsiGetActiveDatabase(hInstall);
MsiDatabaseOpenView(hDB,
TEXT("SELECT * FROM `Feature` WHERE `Feature`='MakeMeRequired'"),
&hView);

MsiViewExecute(hView, 0);
MsiViewFetch(hView, &hRecord);

MsiViewModify(hView, MSIMODIFY_DELETE, hRecord);

INT attr = MsiRecordGetInteger(hRecord, 8);
MsiRecordSetInteger(hRecord, 8, attr + 16); // 16 = ...DisallowAbsent

MsiViewModify(hView, MSIMODIFY_INSERT_TEMPORARY, hRecord);

MsiViewClose(hView);
return ERROR_SUCCESS;
}