RegDBKeyExists function fails to read in Installshield

2.6k views Asked by At

We have developed MSI package in Installshiled 2008 Premier Edition and project type is Installscript MSI, recently we bought 2011 and upgrdaded our project to 2011.

In earlier version we used to check the registry entries for Microsoft SQL Express and its path is

**HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL**

Now a new require came to create a package for 64 bit O.S., since O.S. is 64-bit but the registry path for SQL Express in 64 bit is

**HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL**

The registry function RegDBKeyExists is to check SQL registry's presence, but function is returning a negative number as -2147483646 and fails to read.

setting the option REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY will not help because we not reading 64 bit related registry Hive.

2

There are 2 answers

1
Michael Urman On

Don't worry about it so much; Registry Reflection makes this do the right thing without extra code. When a 32-bit app accesses HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL on a 64-bit machine it will be redirected and see HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL (unless it passes the KEY_WOW64_64KEY - equivalent to the REGDB_OPTION_WOW64_64KEY).

If you hardcode the Wow6432Node key into your query, this scenario will tend to see the keys under a path including HKLM\Software\Wow6432Node\Wow6432Node\... and be unable to find the key you meant to find.

0
BuvinJ On

As a follow up to Michael's answer and my comment (i.e. question), here's an InstallScript function to toggle registry reflection:

prototype void EnableRegistryReflection( BOOL );
///////////////////////////////////////////////////////////////////////////////
//                                                                           
// Function:  EnableRegistryReflection
//                                                                           
//  Purpose:  Toogle the automatic conversion of registry keys from 64 to 32 bit equalivents.
//            This is enabled by default.
//                                                                           
///////////////////////////////////////////////////////////////////////////////
function void EnableRegistryReflection( bEnable )
begin
    if( bEnable ) then
        REGDB_OPTIONS = REGDB_OPTIONS & ~REGDB_OPTION_WOW64_64KEY;
    else
        REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;       
    endif;
end;