Hi Robert

Some old code gleaned sometime ago from the net - hope it helps

function FindAssociatedApp (const Ext : string) : string;
// adapted by HAB from community.borland.com Question and Answer Database
// Article #15801: Retrieving the program that is associated with a given 
extension
// 16-bit sections removed
var
  reg: TRegistry;
  s : string;
begin
  s := '';
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CLASSES_ROOT;
  if reg.OpenKey('.' + ext + '\shell\open\command',
                 false) <> false then begin
  {The open command has been found}
    s := reg.ReadString('');
    reg.CloseKey;
  end else begin
  {perhaps there is a system file pointer}
    if reg.OpenKey('.' + ext,
                   false) <> false then begin
      s := reg.ReadString('');
      reg.CloseKey;
      if s <> '' then begin
     {A system file pointer was found}
        if reg.OpenKey(s + '\shell\open\command',
                       false) <> false then
     {The open command has been found}
          s := reg.ReadString('');
        reg.CloseKey;
      end;
    end;
  end;
 {Delete any command line, quotes and spaces}
  if Pos('%', s) > 0 then
    Delete(s, Pos('%', s), length(s));
  if Pos('/', s) > 0 then
    Delete(s, Pos('/', s), length(s));     // delete switches
  if Pos('-', s) > 0 then
    Delete(s, Pos('-', s), length(s));     // delete switches
  if ((length(s) > 0) and
      (s[1] = '"')) then
    Delete(s, 1, 1);
  if ((length(s) > 0) and
      (s[length(s)] = '"')) then
    Delete(s, Length(s), 1);
  while ((length(s) > 0) and
         ((s[length(s)] = #32) or
          (s[length(s)] = '"'))) do
    Delete(s, Length(s), 1);
  result := s;
end;

Neil

----- Original Message -----
From: "Robert Meek" <[EMAIL PROTECTED]>
To: <[email protected]>
Date: Mon, 19 May 2008 06:10:45 -0400
Subject: Help w/Registered File Types

> Morning all,
>       I have an urgent need that I hope someone here can help me figure
> out how to handle, involving how to find out the full path and filename of
> an application via it being the registered file type for a selected data
> file!
>       In my application, the user selects a data file, for example a .doc
> file which on most systems will be registered to open with Microsoft Word.
> How can my application find out if it has a registered application, what its
> registered application is, and return the path and filename of it to the
> user without actually launching the data file?
>       Thanx in advance for any help! 
> 
> from Robert Meek dba "Tangentals Design"
> e-mail: [EMAIL PROTECTED]
> Freelance Windows Programming for XP and Vista 
> Also proud to be a Moderator of the "Delphi-List" at elists.org
> 
> "Reality cannot be explained...only enjoyed or endured as your current
> perspective allows!"
> 
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> 
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to