Condition on Checking Windows Registry in the Case of a Variable Windows Registry Path

Condition on Checking Windows Registry in the Case of a Variable Windows Registry Path

Summary

This article discusses how to specify a condition for checking the Windows Registry in the case of a variable Windows Registry path.

Project Type

Basic MSI

Problem Description

During installation of software, the DatabaseFolder Dialog is displayed and the user may choose a folder and that folder path is stored in the [DATABASEDIR] property.

From this, a registry value is created:

Path = "HKEY_LOCAL_MACHINE\SOFTWARE\TEST Abc\[REGISTRY_SETUP_PATH]"

where [REGISTRY_SETUP_PATH] is a property that will be set to different values depending on release flags

The value name = "CommonFilesPath"
The value data = "[DATABASEDIR][CommonFilesDirectoryName]"

[DATABASEDIR]= Value entered in dialog "DatabaseFolder"
[CommonFilesDirectoryName]= Property that will be set to different values depending on release flags.

What is the condition if this Windows Registry value "CommonFilesPath" on path "HKEY_LOCAL_MACHINE\SOFTWARE\TEST Abc\[REGISTRY_SETUP_PATH]" already exists before then install starts? In this case this Windows Registry value should not be modified and the DatabaseFolder Dialog should not be displayed.

Solution

This can be achieved by using the following InstallScript code:

1. RegDBGetKeyValueEx - Use this function to get the Windows Registry value.

function CheckIfCFRegistryValueExists(hMSI)
STRING sRegistrySetupPath;
NUMBER nRegistrySetupPathSize, nType;
STRING sRegKey, sRegName, sRegValue, sErrorCode, szMsg;
NUMBER nRegType, nRegSize, nErrorCode;
STRING sCFRegistryValueExists;
NUMBER nCFRegistryValueExistsSize;
begin
//Find exact path to registry.
MsiGetProperty (hMSI, "REGISTRY_SETUP_PATH", sRegistrySetupPath, nRegistrySetupPathSize);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
REGDB_OPTIONS = REGDB_OPTION_WOW64_64KEY;
sRegKey = "SOFTWARE\\TEST Abc\\" + sRegistrySetupPath;
sRegName = "CommonFilesPath";
sRegValue = "NONE";
nRegType = REGDB_STRING;
nRegSize = -1;

//Get value from registry
if (RegDBGetKeyValueEx (sRegKey, sRegName, nRegType, sRegValue, nRegSize) < 0) then
//Registry value doesn't exists. Set CFRegistryValueExists to "FALSE"
MsiSetProperty(hMSI, "CFRegistryValueExists", "FALSE");
else
//Registry value exists. Set CFRegistryValueExists to "TRUE"
MsiSetProperty(hMSI, "CFRegistryValueExists", "TRUE");
endif;

MsiGetProperty (hMSI, "CFRegistryValueExists", sCFRegistryValueExists, nCFRegistryValueExistsSize);
end;

Note: The InstallScript code is triggered by an InstallScript custom action configured for Immediate Execution.

2. Add a condition for the DatabaseFolder Dialog.

The condition should be specified for the NewDialog Event the Next button that navigates to the DatabaseFolder Dialog.

In this case, the condition would be: NOT CFRegistryValueExists

Was this article helpful? Yes No
No ratings
Version history
Revision #:
7 of 7
Last update:
‎Feb 25, 2021 10:03 AM
Updated by: