cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Bajuyngaonau1
Level 3

InstallScript Project Registry

How to delete a registry key during installation and during uninstall ?

HCKU\SOFTWARE\MyProgram
HKLM\SOFTWARE\MyProgram
HKLM\Wow6432Node\MyProgram

P.S

Nothing found how to do it !
Labels (1)
0 Kudos
(11) Replies
PlinyElder
Level 7

Installscript:

export prototype RemoveRegistry(HWND);

function RemoveRegistry(hMSI)

begin
RegDBSetDefaultRoot(HKEY_CURRENT_USER); //Set Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); // Change Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key

REGDB_OPTIONS = REGDB_OPTION_WOW64_64KEY; //Set root key to look in the 64bit part of the registry
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key
end;


Then create a custom action to point to this Installscript function and run it on install and uninstall
0 Kudos
Bajuyngaonau1
Level 3

PlinyElder wrote:
Installscript:

export prototype RemoveRegistry(HWND);

function RemoveRegistry(hMSI)

begin
RegDBSetDefaultRoot(HKEY_CURRENT_USER); //Set Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); // Change Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key

REGDB_OPTIONS = REGDB_OPTION_WOW64_64KEY; //Set root key to look in the 64bit part of the registry
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key
end;


Then create a custom action to point to this Installscript function and run it on install and uninstall



How to create a custom action ?
0 Kudos
Bajuyngaonau1
Level 3

Error C8079
0 Kudos
PlinyElder
Level 7

Bajuyngaonau1 wrote:
How to create a custom action ?


Custom Actions and Sequences under the Behavior and Logic section. Create an Installscript custom action and assign it to your installscript function.

My example script is written in Installshield 2014 but i dont think it should have problems running in IS2015
0 Kudos
Bajuyngaonau1
Level 3

PlinyElder wrote:
Custom Actions and Sequences under the Behavior and Logic section. Create an Installscript custom action and assign it to your installscript function.

My example script is written in Installshield 2014 but i dont think it should have problems running in IS2015



This is not present there is only Basic MSI Project
0 Kudos
Bajuyngaonau1
Level 3

What to do ?
0 Kudos
Bajuyngaonau1
Level 3

Can you give me a script?
0 Kudos
PlinyElder
Level 7

Oh i see that you are using and Installscript project so yes you wont see a spot for Custom Actions.

You will have to manually insert the installscript code into the installer sequence. All that is under the Installscript section. You can select the OnBegin and OnUninstall selections in the drop down menu and set your required actions

Or use the Registry option under the System Configuration section
0 Kudos
Bajuyngaonau1
Level 3

I give up ! Here is my script !
0 Kudos
Bajuyngaonau1
Level 3

Do not remove !
0 Kudos
PlinyElder
Level 7

Made a few adjustments, just replace the Setup.rul code with the code below and it will work
Also i did this in the evaluatino version of Installshield 2015 so just rebuild and it will work


//===========================================================================
//
// 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"
export prototype RemoveRegistry();

//---------------------------------------------------------------------------
// OnFirstUIBefore
//
// First Install UI Sequence - Before Move Data
//
// The OnFirstUIBefore event is called by OnShowUI when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIBefore()
number nResult, nLevel, nSize, nSetupType;
string szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;
string szName, szCompany, szTargetPath, szDir, szFeatures;
BOOL bLicenseAccepted;
begin

// 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 = COMPLETE;
szDir = TARGETDIR;
szName = "";
szCompany = "";
bLicenseAccepted = FALSE;

// Beginning of UI Sequence
Dlg_Start:
nResult = 0;

Dlg_SdWelcome:
szTitle = "";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdWelcome)
nResult = SdWelcome( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdWelcome)
if (nResult = BACK) goto Dlg_Start;

Dlg_SdLicense2:
szTitle = "";
szOpt1 = "";
szOpt2 = "";
//{{IS_SCRIPT_TAG(License_File_Path)
szLicenseFile = SUPPORTDIR ^ "License.rtf";
//}}IS_SCRIPT_TAG(License_File_Path)
//{{IS_SCRIPT_TAG(Dlg_SdLicense2)
//nResult = SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE );
//}}IS_SCRIPT_TAG(Dlg_SdLicense2)
if (nResult = BACK) then
goto Dlg_SdWelcome;
else
bLicenseAccepted = TRUE;
endif;

Dlg_SdRegisterUser:
szMsg = "";
szTitle = "";
//{{IS_SCRIPT_TAG(Dlg_SdRegisterUser)
//nResult = SdRegisterUser( szTitle, szMsg, szName, szCompany );
//}}IS_SCRIPT_TAG(Dlg_SdRegisterUser)
if (nResult = BACK) goto Dlg_SdLicense2;

Dlg_SetupType2:
szTitle = "";
szMsg = "";
nResult = CUSTOM;
//{{IS_SCRIPT_TAG(Dlg_SetupType2)
//nResult = SetupType2( szTitle, szMsg, "", nSetupType, 0 );
//}}IS_SCRIPT_TAG(Dlg_SetupType2)
if (nResult = BACK) then
goto Dlg_SdRegisterUser;
else
nSetupType = nResult;
if (nSetupType != CUSTOM) then
szTargetPath = TARGETDIR;
nSize = 0;
FeatureCompareSizeRequired( MEDIA, szTargetPath, nSize );
if (nSize != 0) then
MessageBox( szSdStr_NotEnoughSpace, WARNING );
goto Dlg_SetupType2;
endif;
endif;
endif;

Dlg_SdAskDestPath2:
if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType2;
szTitle = "";
szMsg = "";
if (nSetupType = CUSTOM) then
//{{IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
nResult = SdAskDestPath2( szTitle, szMsg, szDir );
//}}IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
TARGETDIR = szDir;
endif;
if (nResult = BACK) goto Dlg_SetupType2;

Dlg_SdFeatureTree:
if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2;
szTitle = "";
szMsg = "";
szFeatures = "";
nLevel = 2;
if (nSetupType = CUSTOM) then
//{{IS_SCRIPT_TAG(Dlg_SdFeatureTree)
//nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel );
//}}IS_SCRIPT_TAG(Dlg_SdFeatureTree)
if (nResult = BACK) goto Dlg_SdAskDestPath2;
endif;

Dlg_SQLServer:
nResult = OnSQLServerInitialize( nResult );
if( nResult = BACK ) goto Dlg_SdFeatureTree;

Dlg_ObjDialogs:
nResult = ShowObjWizardPages( nResult );
if (nResult = BACK) goto Dlg_SQLServer;

Dlg_SdStartCopy2:
szTitle = "";
szMsg = "";
//{{IS_SCRIPT_TAG(Dlg_SdStartCopy2)
nResult = SdStartCopy2( szTitle, szMsg );
//}}IS_SCRIPT_TAG(Dlg_SdStartCopy2)
if (nResult = BACK) goto Dlg_ObjDialogs;

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

return 0;
end;



//---------------------------------------------------------------------------
// OnFirstUIAfter
//
// First Install UI Sequence - After Move Data
//
// The OnFirstUIAfter event called by OnShowUI after the file transfer
// of the setup when the setup is running in first install mode. By default
// this event displays UI that informs the end user that the setup has been
// completed successfully.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIAfter()
STRING szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
NUMBER bvOpt1, bvOpt2;
begin

ShowObjWizardPages(NEXT);

szTitle = "";
szMsg1 = "";
szMsg2 = "";
szOpt1 = "";
szOpt2 = "";
bvOpt1 = FALSE;
bvOpt2 = FALSE;

//{{IS_SCRIPT_TAG(Dlg_SdDinishEx)
if ( BATCH_INSTALL ) then
SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
else
SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
endif;
//}}IS_SCRIPT_TAG(Dlg_SdDinishEx)

// Uninstall registry entries
RemoveRegistry();
end;

//---------------------------------------------------------------------------
// OnMaintUIBefore
//
// Maintenance UI Sequence - Before Move Data
//
// The OnMaintUIBefore event is called by OnShowUI when the setup is
// running in maintenance mode. By default this event displays UI that
// allows the end user to add or remove features, repair currently
// installed features or uninstall the application.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMaintUIBefore()
number nResult, nType;
string szTitle, szMsg;
begin

// nType defaults to MODIFY.
nType = MODIFY;

//Initialize SQL
OnSQLServerInitializeMaint();

// Beginning of UI Sequence
Dlg_Start:

// Added in Version 9.5 - Support for REMOVEONLY option.
if( !REMOVEONLY ) then
// In standard mode show maintenance dialog
Disable( BACKBUTTON );
nType = SdWelcomeMaint( szTitle, szMsg, nType );
Enable( BACKBUTTON );
nResult = NEXT;
else
// Hide the initial progress dialog as otherwise the user can
// click on it, and hide the MessageBox.
Disable( DIALOGCACHE );

// In RemoveOnly mode, set to remove.
nType = REMOVEALL;
endif;

// Show Uninstall Confirmation Dialog
if ( nType = REMOVEALL ) then
nResult = MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO );
if (nResult != IDYES ) then

if( REMOVEONLY ) then
// In REMOVEONLY mode, abort the setup.
abort;
else
// In non-REMOVEONLY mode, redisplay the previous dialog.
goto Dlg_Start;
endif;

endif;
endif;

Dlg_SdFeatureTree:
if ( nType = MODIFY ) then
szTitle = "";
szMsg = SdLoadString( SD_STR_COMPONENT_MAINT_MSG );
nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, "", -1 );
if ( nResult = BACK ) goto Dlg_Start;
endif;

Dlg_ObjDialogs:
nResult = ShowObjWizardPages( nResult );
if ( ( nResult = BACK ) && ( nType != MODIFY ) ) goto Dlg_Start;
if ( ( nResult = BACK ) && ( nType = MODIFY ) ) goto Dlg_SdFeatureTree;

switch(nType)

case REMOVEALL:

// Ensure that all previously installed features are removed.
FeatureRemoveAllInMediaAndLog();

// Uninstall registry entries
RemoveRegistry();

// Added in 11.0 - Set appropriate StatusEx static text.
SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );

case REPAIR:

// Changed for DevStudio 9, Disk1 files are now always updated when installed
// so when running from ADDREMOVE we need to prevent these files from being
// updated since this will result in files being updated that are locked by the setup.
// Updating these files when running from ADDREMOVE should not be needed since updates
// are not run directly from Add/Remove.
if( ADDREMOVE ) then
// Reinstall all previously installed features, except
// disk1 features.
FeatureUpdate( "" );
else
// Reinstall all previously installed features.
FeatureReinstall();
endif;

// Added in 11.0 - Set appropriate StatusEx static text.
SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REPAIR ) );

case MODIFY:

// Added in 11.0 - Set appropriate StatusEx static text.
SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_MODIFY ) );

endswitch;

end;



function RemoveRegistry()
begin
RegDBSetDefaultRoot(HKEY_CURRENT_USER); //Set Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key
//MessageBox("Deleted HKEY_CURRENT_USER", INFORMATION);

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); // Change Root key
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key
//MessageBox("Deleted HKEY_LOCAL_MACHINE\", INFORMATION);

REGDB_OPTIONS = REGDB_OPTION_WOW64_64KEY; //Set root key to look in the 64bit part of the registry
RegDBDeleteKey("SOFTWARE\\MyProgram"); //Delete Key
end;

0 Kudos