MDAC - How to detect version of MDAC installed

From ISXKB

Revision as of 12:03, 26 November 2007 by Bobbobber23 (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Introduction

This script is useful to detect if and which version of MDAC is installed on the target computer. The example checks if there is at least MDAC version 2.60 available. The setup cannot continue if either MDAC is not installed or its version is too low.

The code

[Setup]
AppName=MDAC
AppVerName=MDAC
DefaultDirName={pf}\MDAC
DisableStartupPrompt=true
Uninstallable=false
DisableDirPage=true
OutputBaseFilename=MDAC

[Code]

procedure DecodeVersion (verstr: String; var verint: array of Integer);
var
  i,p: Integer; s: string;
begin
  // initialize array
  verint := [0,0,0,0];
  i := 0;
  while ((Length(verstr) > 0) and (i < 4)) do
  begin
  	p := pos ('.', verstr);
  	if p > 0 then
  	begin
      if p = 1 then s:= '0' else s:= Copy (verstr, 1, p - 1);
  	  verint[i] := StrToInt(s);
  	  i := i + 1;
  	  verstr := Copy (verstr, p+1, Length(verstr));
  	end
  	else
  	begin
  	  verint[i] := StrToInt (verstr);
  	  verstr := '';
  	end;
  end;

end;

function GetMDACVersion (): String;
var
  sVersion:  String;
begin
  sVersion := '';
  GetVersionNumbersString (ExpandConstant('{cf}\System\Ado\msado15.dll') , sVersion );
  Result := sVersion;
end;

// This function compares version strings
// return -1 if ver1 < ver2
// return  0 if ver1 = ver2
// return  1 if ver1 > ver2
function CompareVersion (ver1, ver2: String) : Integer;
var
  verint1, verint2: array of Integer;
  i: integer;
begin

  SetArrayLength (verint1, 4);
  DecodeVersion (ver1, verint1);

  SetArrayLength (verint2, 4);
  DecodeVersion (ver2, verint2);

  Result := 0; i := 0;
  while ((Result = 0) and ( i < 4 )) do
  begin
  	if verint1[i] > verint2[i] then
  	  Result := 1
  	else
      if verint1[i] < verint2[i] then
  	    Result := -1
  	  else
  	    Result := 0;
  	i := i + 1;
  end;

end;

function InitializeSetup (): Boolean;
begin
  if CompareVersion (GetMDACVersion (), '2.60') < 0 then
  begin
    MsgBox ('The version of MDAC currently installed on this computer is ' + GetMDACVersion () +
      '. In order to continue Setup requires at least MDAC version 2.60. Please install at least MDAC version 2.60 and run the Setup again.',  mbInformation, MB_OK );
    Result := false;
  end
  else
    Result := true;
end;


Alternative Method

This alternative method make use of the CompareVersion() function from the above example

function IsMdacDetected(mdacMinVerNeeded: String): boolean;
var
    mdacVer: String;
    vercomp: Integer;
begin
    RegQueryStringValue(HKLM, 'Software\Microsoft\DataAccess', 'FullInstallVer', mdacVer);

    //Was there any data returned?
    if Length( mdacVer ) > 0 then
    begin
      //Compare versions
      vercomp := CompareVersion(mdacVer, mdacMinVerNeeded);

      //Version smaller
      if vercomp < 0 then
      begin
        Result := false;
      end;

      //Same version
      if vercomp = 0 then
      begin
        Result := true;
      end;

      //Version bigger
      if vercomp > 0 then
      begin
        Result := true;
      end;
    end
    else
    begin
      Result := false;
    end;
end;

See also

External links

Personal tools
Ads: