find generic path of MySQL in registry as it creates version specific entry as key in registry

2.5k views Asked by At

i need to check the sql server version every time my application installation begins through inno setup. but as sql creates the server version specific entry(like MySQL Server 5.1) as key in the registry, so i have to give the path like

HKLM\SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1

while checking the version.
but when i install the sql server having version other than 5.1, it checks on the above path, it couldn't find. so again installation begins although it is already installed. so i want some generic path like

HKLM\SOFTWARE\Wow6432Node\MySQL AB\MySQL Server

which is not version specific. so that i can easily retreive the value from the MySQL key and check for it.My Code is

function fCheckMySQLInstall():boolean;
    var
  mysqlVersion : string;
begin
  bIsMyQLInstalled := False;
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.1', 'Version', mysqlVersion) = true then
    if CompareStr(mysqlVersion,'5.1') >= 0  then
      bIsMyQLInstalled := True;

  Result := bIsMyQLInstalled;
end;

as the path is /MySQL Server 5.1 which is not correct. should be generic for all version so that i can check for other version. Solutions are welcome.

2

There are 2 answers

0
Ranjit Singh On BEST ANSWER

what i have done is. get all the versions of mySQL server from the registry(for how see the code below!). after extracting all the versions, compare the version of mysql to be installed to extracted version and decide whether to install or not. detailed explanantion is given in mycode.

if RegGetSubkeyNames(HKLM, URL, mysqlVersion) then
  begin
    counter := 0;
    specificVersion := '';
    for mysqlVersionIteration := 0 to GetArrayLength(mysqlVersion)-1 do begin
      specificVersion := mysqlVersion[mysqlVersionIteration];
     res := copy(specificVersion,1,12);
     if(res = 'MySQL Server')then
       if RegQueryStringValue(HKLM, URL+'\'+specificVersion, 'Version', Version) = true then
       begin
           SetArrayLength(extractedVersion, counter + 1);
           extractedVersion[counter] := Version;
           counter := counter + 1;
       end;    
    end;
    for CompareVersionCount:= 0 to GetArrayLength(extractedVersion) - 1 do begin 
        alreadyVersionExists:= copy(extractedVersion[CompareVersionCount],1,3);
        if CompareStr(alreadyVersionExists,'{#MySQLVersion}') >= 0  then
        bIsMyQLInstalled := True;
    end;
  end; 
  1. here URL is "SOFTWARE\Wow6432Node\MySQL AB" in case of win64 and 'SOFTWARE\MySQL AB' in case of win32
  2. iterate through all the subkeys.
  3. extract first 12 letters, because there might be other subkeys.
  4. if that extracted letter is MySQL then the key must have mySQL version.
  5. extract the version of that particular key.
  6. put all the version already present in the system in extractedVersion array.
  7. at last iterate through the extractedVersion array and compare it to version of mySQL to be installed and decide whether to install or not.

By this method my installer does what i supposed to do.

2
Marco van de Voort On

So basically you must enumerate the keys under 'SOFTWARE\Wow6432Node\MySQL AB\' using RegEnumKey(ex) and do the matching to "MySQL Server Vx.y" yourself, and determining highest version from that.

The Delphi/FreePascal registry unit provide functionality for enumerating keys that way, in Inno Setup you can use the RegGetSubkeyNames function for that.