Link to home
Start Free TrialLog in
Avatar of Stream12
Stream12

asked on

Open assosiated programs for assosiated files.

I want to make a small prog to open a powerpoint presentation thru powerpoint automaticly.

I just want to get the assosiated program & parameters for a eg. extention '.pps'.

(I know I can just dubble click on the file, but I want to give this to some people that doesn't understand the concept)
ASKER CERTIFIED SOLUTION
Avatar of Motaz
Motaz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SimesA
SimesA

This code gets the associated program:

function GetAssociateFileType(const FileType: string): string;
var
  reg: TRegistry;
  FileTypeName: string;
  p: integer;
begin
  result := '';
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_CLASSES_ROOT;
    if reg.OpenKey(FileType, false) then begin
      FileTypeName := reg.ReadString('');
      reg.CloseKey;
    end;

    reg.RootKey := HKEY_CLASSES_ROOT;
    if reg.OpenKey(FileTypeName + '\Shell\Open\Command', false) then begin
      result := reg.ReadString('');
      reg.CloseKey;
    end;
    if result <> '' then
      if result[1] = '"' then begin
        delete(result, 1, 1);
        p := Pos('"', result);
        if p <> -1 then
          delete(result, p, length(result) - p + 1);
      end;
  finally
    reg.free;
  end;
end;
Avatar of Stream12

ASKER

Thank you both,

I tried both answers and both work. Wish I could split the points.

I chose Motaz's anwser because it's shorter.

Also, with SimesA solution I don't get the parameters on output.