
william.ctr.pacilio1.5524922118593489E12 asked a question.
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.
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;
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,
Thanks for the info