2004. november 8., hétfő

Check if Microsoft Word is installed?


Problem/Question/Abstract:

How can I check if Microsoft Word is installed?

Answer:

Solve 1:

Important: this method will only succeed if Microsoft Word 95 or higher is installed.

uses
  ..., Registry;

function IsMicrosoftWordInstalled: Boolean;
var
  Reg: TRegistry;
  S: string;
begin
  Reg := TRegistry.Create;
  with Reg do
  begin
    RootKey := HKEY_CLASSES_ROOT;
    Result := KeyExists('Word.Application');
    Free;
  end;
end;


Solve 2:

function MSWordIsInstalled: Boolean;
begin
  Result := AppIsInstalled('Word.Application');
end;

function AppIsInstalled(strOLEObject: string): Boolean;
var
  ClassID: TCLSID;
begin
  Result := (CLSIDFromProgID(PWideChar(WideString(strOLEObject)), ClassID) = S_OK)
end;

Nincsenek megjegyzések:

Megjegyzés küldése