Search code examples
sql-serverinstallationregistryinno-setup

RegQueryStringValue not returning MULTI_SZ values


I'm developing an installer for a software which uses SQL Server, so I'm checking if it's installed using the code below, running on Windows 7 x64 and Inno Setup 5.5.4 (tested both on Ansi and Unicode):

function IsSQLServerInstalled(): Boolean;
var
  version: string;
  instances: String;
  instancesList: TArrayOfString;
  i: Integer;
begin
  if (not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Microsoft SQL Server')) then begin
    Result := False;
  end
  else begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Microsoft SQL Server', 'InstalledInstances', instances);
    // code goes on...

Not a single problem here, since the code is compiling just fine, but when I debug, the "instances" variable is kept blank, albeit I have this MULTI_SZ register value containing the installed instances on my machine. Where it should return something like "INSTANCE1 INSTANCE2" and so on, it gives me only a "blank" ''

RegKeyExists function executes fine too, so the else block is being hit normally.

What I'm doing wrong?


Solution

  • I must use RegQueryMultiStringValue function, which works properly on MULTI_SZ values. Thank you all.