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

Accessing registry fails in OnEnd

For some reason my RegDBGetKeyValueEx call in the OnEnd function fails everytime - the key exists and has a value, the exact same call works when called in other parts of the script and only fails in this function.

Does anyone know why this would fail?

Here's the code:

function OnEnd()
STRING componentSelected, tempKey;
BOOL result;
begin
tempKey = TEMP_REG_KEY;

// If not removing everything
if (REMOVEALLMODE == 0 && MAINTENANCE == 0) then
// If component is selected for install
result = getKeyValue(tempKey, "ComponentSelected", componentSelected);
if (componentSelected= "TRUE") then
MessageBox ("Component selected to install.",INFORMATION);

else
MessageBox ("Component not selected to install.",INFORMATION);

endif;

endif;

deleteKey(tempKey);

return 0;

end;


And for the getKeyValue function - includes plenty of debug messages

prototype BOOL getKeyValue(STRING, STRING, BYREF STRING);

// Assumes STRING value for key
function BOOL getKeyValue(szKey, szName, szValue)
NUMBER nvType, nvSize, result;
STRING szMsg;
begin
// Retrieve key value information.
result = RegDBGetKeyValueEx (szKey, szName, nvType, szValue, nvSize);
if (result < 0) then
MessageBox ("RegDBGetKeyValueEx failed.", SEVERE);
return 1;
else
// Check to see if the value returned is the same as the value set.
if (nvType != REGDB_STRING) then
MessageBox ("Type comparison failed.", SEVERE);
return 1;
endif;

// Display what RegDBGetKeyValueEx retrieved.
szMsg = "%s has value: %s\n\nThis data is %d bytes.";
SprintfBox (INFORMATION, "", szMsg, szName, szValue, nvSize);
endif;
end;
Labels (1)
0 Kudos
(4) Replies
RobertDickau
Flexera Alumni

How is getKeyValue defined? Does its return value "result" tell you anything?
0 Kudos
Branstar
Level 3

Thanks for your reply;

I've added the code for the getKeyValue function to my first post. The 'result' is only the success of the function, the value of the registry is stored in a parameter passed in by reference.
0 Kudos
RobertDickau
Flexera Alumni

Perhaps the registry root you're reading from changes between functions? If so, you'll want another call to RegDBSetDefaultRoot before RegDBGetKeyValueEx.
0 Kudos
Branstar
Level 3

Hurrah! I tried setting the root again as you suggested and the registry operations are now working; thanks for your help 🙂
0 Kudos