cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
agshah
Level 6

Get the Feature selection state from InstallScript MSI project

Hi all,

I am using InstallScript MSI project in InstallShield 2021.

I have some features and want to know which ones the user selected from the GUI. I tried below three approaches but none of them indicate that the feature is selected. I tried using both the feature name as well as the name that is displayed in the GUI.

More specifically I want to get this info from Setup.rul from function OnFirstUIAfter() or other functions in that script.

I tried:

FeatureGetData (MEDIA, "New_Feature", FEATURE_FIELD_DESCRIPTION, nvResult, svResult);
It says feature not selected even though it was selected.

nResult = FeatureIsItemSelected (MEDIA,  "New_Feature");
It says feature not selected even though it was selected.

nReturnCode = MsiGetFeatureState (ISMSI_HANDLE, "New_Feature", nvInstallState, nvActionState);
it says "An unrecognized product or feature was specified";

Appreciate any help.
Am I not specifying the feature name correctly? Or do I need to use some other approach in InstallScript MSI project to detect feature selection state from installscript ?

thanks in advance.

Labels (1)
0 Kudos
6 Replies
agshah
Level 6

Folks, appreciate if anyone can help out with this...

0 Kudos
Revenera_Ian
Revenera Moderator Revenera Moderator
Revenera Moderator

Hi @agshah,

Thank you for your post.

Please accept our apologies for the delayed response.

I tested and confirmed that the following InstallScript code worked for me in an InstallScript MSI project in the OnFirstUIBefore event handler function:

 

 

//===========================================================================
//
//  File Name:    Setup.rul
//
//  Description:  Blank setup main script file
//
//  Comments:     Blank setup is an empty setup project. If you want to
//				  create a new project via. step-by step instructions use the
//				  Project Assistant.
//
//===========================================================================

// Included header files ----------------------------------------------------
#include "ifx.h"

// Note: In order to have your InstallScript function executed as a custom
// action by the Windows Installer, it must be prototyped as an 
// entry-point function.

// The keyword export identifies MyFunction() as an entry-point function.
// The argument it accepts must be a handle to the Installer database.
    
/* export prototype MyFunction(HWND); */

//---------------------------------------------------------------------------
// OnFirstUIBefore
//
// The OnFirstUIBefore event is called by the framework when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//---------------------------------------------------------------------------
function OnFirstUIBefore()
    NUMBER nResult, nSetupType, nvSize, nUser, nResultFeatureA, nResultFeatureB;
    STRING szTitle, szMsg, szQuestion, svName, svCompany, szFile;
    STRING szLicenseFile;
	BOOL bCustom, bIgnore1, bIgnore2;
begin	
    // TO DO: if you want to enable background, window title, and caption bar title                                                                   
    // SetTitle( @PRODUCT_NAME, 24, WHITE );                                        
    // SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION ); 	                  
    // Enable( FULLWINDOWMODE );						   
    // Enable( BACKGROUND );							  
    // SetColor(BACKGROUND,RGB (0, 128, 128));					   

    // Added in InstallShield 15 - Show an appropriate error message if
    // -removeonly is specified and the product is not installed.
    if( REMOVEONLY ) then
        Disable( DIALOGCACHE );
		szMsg = SdLoadString( IDS_IFX_ERROR_PRODUCT_NOT_INSTALLED_UNINST );
   		SdSubstituteProductInfo( szMsg );
		MessageBox( szMsg, SEVERE );
		abort;
    endif;
    
	nSetupType = TYPICAL;	

Dlg_SdWelcome:
    szTitle = "";
    szMsg   = "";
    nResult = SdWelcome(szTitle, szMsg);
    if (nResult = BACK) goto Dlg_SdWelcome;
	
	szTitle   = "";
	svName    = "";
    svCompany = "";

Dlg_SdRegisterUser:
    szMsg = "";
    szTitle = "";
    nResult = SdRegisterUser( szTitle, szMsg, svName, svCompany );
    if (nResult = BACK) goto Dlg_SdWelcome;

Dlg_SetupType:
    szTitle = "";
    szMsg   = "";
    nResult = SetupType2(szTitle, szMsg, "", nSetupType, 0);
    if (nResult = BACK) then
        goto Dlg_SdRegisterUser;
    else
	    nSetupType = nResult;
        if (nSetupType != CUSTOM) then
	        nvSize = 0;
	        FeatureCompareSizeRequired(MEDIA, INSTALLDIR, nvSize);
	        if (nvSize != 0) then      
            	MessageBox(szSdStr_NotEnoughSpace, WARNING);
	            goto Dlg_SetupType;
            endif;
			bCustom = FALSE;
			goto Dlg_SQL;
		else
			bCustom = TRUE;
        endif;
    endif;    

Dlg_SdAskDestPath:    	
    nResult = SdAskDestPath(szTitle, szMsg, INSTALLDIR, 0);
    if (nResult = BACK) goto Dlg_SetupType;

Dlg_SdFeatureTree: 
    szTitle    = "";
    szMsg      = "";
    if (nSetupType = CUSTOM) then
		nResult = SdFeatureTree(szTitle, szMsg, INSTALLDIR, "", 2);
		if (nResult = BACK) goto Dlg_SdAskDestPath;  
    endif;

nResultFeatureA = FeatureIsItemSelected(MEDIA, "FeatureA");

if (nResultFeatureA == 1) then
	MessageBox("Feature A is selected.", INFORMATION);
else
	MessageBox("Feature A is not selected.", INFORMATION);
endif;

nResultFeatureB = FeatureIsItemSelected(MEDIA, "FeatureB");

if (nResultFeatureB == 1) then
	MessageBox("Feature B is selected.", INFORMATION);
else
	MessageBox("Feature B is not selected.", INFORMATION);
endif;

Dlg_SQL:
    nResult = OnSQLLogin( nResult );
    if( nResult = BACK ) then
    	if (!bCustom) then
    		goto Dlg_SetupType;    
    	else
    		goto Dlg_SdFeatureTree;
    	endif;
    endif;

Dlg_SdStartCopy:
    szTitle = "";
    szMsg   = "";
    nResult = SdStartCopy2( szTitle, szMsg );			
	
    if (nResult = BACK) then
       goto Dlg_SQL;;
    endif;

    // Added in IS 2009 - Set appropriate StatusEx static text.
    SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) );

    // setup default status
    Enable(STATUSEX);
 
    return 0;
end;

 

 

 


The custom InstallScript code is between:

Dlg_SdFeatureTree

and:

Dlg_SQL

Please give this a try. Does this work for you?

Also, is this a first-time install, a minor upgrade, or a major upgrade? In which scenario does this issue occur?

Please let us know if you have any questions or concerns. Thanks!

0 Kudos

thanks very much. I will try it out and get back to you.

0 Kudos
Revenera_Ian
Revenera Moderator Revenera Moderator
Revenera Moderator

you're very welcome, @agshah. I'm happy to help. Sounds good.

Please let us know if you have any questions or concerns. Thanks!

0 Kudos

thanks for you help. It works for install scenario. But not for uninstall.

More specifically, below is how we perform some uninstall tasks before the files get removed.

I have a InstallScript type Custom Action which invokes an event handler function such as below in setup.rul.

function UnInstallTasks1(hMSI) begin end;

When this UnInstallTasks1 function  is invoked,  FeatureIsItemSelected is not able to detect that any of the features are installed locally. Hence I cannot perform uninstall task for features begin uninstalled.

I have placed the custom Action after Sequences -> Installation -> Execute -> RemoveEnvironmentStrings.

With you help, the install works. But not the above uninstall scenario.
how can I detect which features were installed that are being uninstalled? So I can do the needful.

BTW, we are using the above approach to perform uninstall tasks because that is the way to make automatic upgrades work. 


If we perform uninstall tasks in OnMaintUIBefore, automatic upgrades will not work. This is something InstallShield had confirmed and had recommended that we take this custom Action approach. 
This approach would work for both below cases:

- simply uninstall the product that is installed.

- when installing a newer version and using automatic upgrade, the custom action will invoked the function allowing us to perform some uninstall task for the existing version that is being removed during the upprade.

For our project that does not have features, this approach works. But now we need to add features and so  we need to detect which feature is being removed. 

Note that at this point I am not doing automatic upgrade but simply trying to uninstall the existing project but not able to detect the features that are being removed.

thanks in advance. Appreciate your help to get this to work.

 

0 Kudos
Revenera_Ian
Revenera Moderator Revenera Moderator
Revenera Moderator

Hi @agshah,

Thank you for your reply.

We'll need a support ticket (case) to track this issue. Could you please open a case with our Support Team, about this issue, by email at support@revenera.com or by phone at (877) 279-2853, as long as you have a valid, active, unexpired technical support contract (maintenance plan)?

Please let us know if you have any questions or concerns. Thanks!

0 Kudos