2009. augusztus 12., szerda

How to get the Word version on a client PC


Problem/Question/Abstract:

Using D6 I need to extract the Word version on the client computer. The options are Word97, Word2000 and WordXP.

Answer:

function GetCurrentWordMajorVersion: Integer;
var
  vRegistry: TRegistry;
  vVersionStr: string;
  vVersion: string;
begin
  Result := -1;
  vRegistry := TRegistry.Create(KEY_READ);
  try
    vRegistry.RootKey := HKEY_CLASSES_ROOT;
    if vRegistry.OpenKeyReadOnly('Word.Application\CurVer') then
    begin
      {Get the default value: 'Word.Application.10'}
      vVersionStr := vRegistry.ReadString('');
      {Extract the major version from the string}
      vVersion := System.Copy(vVersionStr, Succ(LastDelimiter('.', vVersionStr)),
        MAXINT);
      {8=Word97, 9=Word2000, 10=Word2002, etc.}
      Result := StrToIntDef(vVersion, -1);
    end;
  finally
    vRegistry.Free;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése