0
votes

I have a custom action in an Installshield Basic MSI project to find out the version of SQL Server from registry.

RegKey2012 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\" & _
             "Microsoft SQL Server\MSSQL11.MSSQLSERVER\"
If RegKeyExists(RegKey2012) Then 
  WScript.StdOut.Write("2012") 
Else 
  WScript.StdOut.Write("2008R2") 
End If 

Function RegKeyExists(Key) 
  Dim oShell, entry 
  On Error Resume Next 
  Set oShell = CreateObject("WScript.Shell") 
  entry = oShell.RegRead(Key) 
  If Err.Number <> 0 Then 
    Err.Clear 
    RegKeyExists = False 
  Else 
    Err.Clear 
    RegKeyExists = True 
  End If 
End Function

The installer works fine on a Windows 7 machine. The above script works fine in isolation on a Windows Server 2012 machine. However when I run the installer (as ADMIN) on windows server 2012, it does not work as expected and the error description is - It cannot find the registry key.

Any ideas.

1
Are you maybe running into a 32 vs 64 bit registry redirect issue?DaveE
no idea.. I m a 2/10 in Installshield...Can you please elaborate...The registry key is same in both 32 and 64 bit machines - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVERSubhasis
32-bit apps on 64-bit Windows have their registry keys redirected to a different location. If your app/installer is 32-bit it might be that its registry lookups are being redirected to that location (...\SOFTWARE\Wow6432Node\...), while your presumably 64-bit SQL Server's registry entries are in the "standard" location. Look up REGDB_OPTION_WOW64_64KEY or WOW64FSREDIRECTION in the IS help.DaveE
Thanks DaveE. Registry redirect was the issue indeed. It was looking into \SOFTWARE\Wow6432Node\...Found out using Process Moniter. The issue was fixed using the /reg:64 option.Subhasis

1 Answers

1
votes
strkey="HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\Setup" & Chr(34) &  " /v Version /reg:64"

Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("REG QUERY " & Chr(34) & strkey )

strText = objScriptExec.StdOut.ReadAll()
if (strText <> "") then
WScript.echo "2012"
else
WScript.echo "2008R2"
end if

Note the /reg:64 option in line1. Without that it was not working.