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

Assign a registry value to a Admin variable

I have a basic MSI package and this is the first bit of InstallScript code that I need to insert. What I would like to do is get a value from my registry and assign it to a variable that I will use during the GUI part of the install. Here is what I have. Please supply a sequence and code snippets.
Regards

Value HKEY_CURRENT_USER\Software\STARS_SW is stored in the registry.
It only has a default entry (set to 3 in this case).
I want to verify the key is there and assigne it to a variable in AdminStudio and then return success or failure

So far I only have this:

szKey = "SOFTWARE\\STARS_SW";
nRootKey = HKEY_LOCAL_MACHINE;
nResult = RegDBSetDefaultRoot (nRootKey);

if (RegDBKeyExist (szKey) < 0) then
MessageBox ("First call to RegDBKeyExist failed.", SEVERE);
else
SprintfBox (INFORMATION, "VERSION", "%s exists.", szKey);
nResult = 1;
endif;
return(nResult);


function GetCurrentVersion(hMSI)
STRING szKey, szClass, szKeyRoot, szMsg, svLogFile;

begin

end

I'm not sure what values to give RegDBGetKeyValueEx since I'm looking for the default and I don't know how to assign the variable.
(3) Replies
Here is my code. I'm not sure what is missing. Also, can someone recommend a location in the AdminStudio sequences to place the custom action? I have it in the Exec sequence after InstallValidate. I can't verify that the script is being run. So far the message boxes do not pop up. I'm not sure if it's the script or the location.... or both :rolleyes:

     
function GetCurrentVersion(hMSI)
STRING szKey,szValue,szName, szClass, svCurrentVersion;
NUMBER nRootKey,nType,nResult,nvSize;
begin
nvSize = -1;
szKey = "SOFTWARE\\STARS_SW";
szValue = "";
szName = "";
nType = REGDB_NUMBER;
nRootKey = HKEY_LOCAL_MACHINE;
svCurrentVersion = "0";

MessageBox ("Looking for REG Key", INFORMATION);

nResult = RegDBSetDefaultRoot (nRootKey);
if (nResult = 0) then
if (RegDBKeyExist (szKey) < 0) then
MessageBox ("First call to RegDBKeyExist failed.", SEVERE);
else
SprintfBox (INFORMATION, "VERSION", "%s exists.", szKey);

nResult = RegDBGetKeyValueEx (szKey, szName, nType, szValue, nvSize);
if(nResult = 0) then
MsiSetProperty( hMSI,"IS_STARS_UPDATE", szValue);
endif;
endif;
endif;

return(nResult);
end;
There's actually two ways to handle this. Creating an InstallScript action to handle it is probably the harder way. However, here's the code that I would use. You'll have to fix the compile errors as I'm doing this from memory:

function GetCurrentVersion(hMSI)

begin
//
// Reset the STARSSW property so that it doesn't exist
//
MsiSetProperty( ISMSI_HANDLE, "STARSSW", "" );
RegDBSetDefaultRoot( HKEY_CURRENT_USER );

szKey = "SOFTWARE\\STARS_SW";
szVName = "";
RegDBGetValueEx( szKey, szVName, REGDB_STRING, szValue, -1 );

if ( szValue != "" ) then
MsiSetProperty( ISMSI_HANDLE, "STARSSW", szValue );
endif;
end

From this point, if STARSSW exists it has the current value from the registry. Otherwise the registry key doesn't exist. This should be an immediate custom action. Use the status of STARSW as a condition on a second New Error custom action.

An easier way is to use a System Search (Behavior and Logic-->System Search). Right-click in the right pane and select Add. Select Registry Value. Select Next. Provide the registry information (leave Registry value blank--this will be the empty value). Select Next. Type in the name of the Property that you want to use. To keep continuity with the above example, use STARSSW. Since you want the install to exit if it's not found, select the second radio button (use as install condition). Select Finish and enter the error string. That's it, you're done.

Hope that helps,
I knew there had to ba an easier way but all the forum posts seemed to point to a InstallScript solution. I'm going to try to get both to work just for fun 😄
Thanks for the info