During setup.exe installation if a particular key exists in registry i want to abort the installation.To achieve this,i am calling install-script function using custom action in install shield project. Install Script code is :
function MyFunction(hMSI)
// To Do: Declare local variables.
STRING szKey;
NUMBER nRootKey;
begin
// Set the root key to HKEY_LOCAL_MACHINE.
nRootKey = HKEY_LOCAL_MACHINE;
if (RegDBSetDefaultRoot (nRootKey) < 0) then
MessageBox ("First call to RegDBSetDefaultRoot failed.", SEVERE);
else
MessageBox ("Root key successfully set to HKEY_LOCAL_MACHINE.",
INFORMATION);
endif;
szKey = "SOFTWARE\\Test";
if (RegDBKeyExist (szKey)< 0) then
MessageBox ("Test is not present", SEVERE);
abort;
endif;
if (RegDBKeyExist (szKey)= 1) then
MessageBox ("Test is present", SEVERE);
abort;
endif;
// To Do: Write script that will be executed when MyFunction is called.
end;
Every time i am getting message "Test is not present" even though key "HKEY_LOCAL_MACHINE\SOFTWARE\Test" is present in registry.
I think i did some what wrong in script or missing something. Please help on this.
https://community.flexerasoftware.com/showthread.php?139026-Check-if-a-registry-key-exists
It's not 100% confirmed in your question, but I would give strong odds that:
If that's all true, the problem is that you have created the key HKEY_LOCAL_MACHINE\SOFTWARE\Test, but your code is checking HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Test instead, due to the registry redirector. To fix this, you should do one of the following:
Note that if this key is created by software outside of your control, you will need to ensure that you are checking for the right location. That will influence whether the first or second bullet is a better choice for your situation. (If the key is fully under your control, you should also think about whether it's using the right location, and change it if it is not.)