Solved

Associated EXE

Posted on 1998-01-15
4
258 Views
Last Modified: 2010-04-04
Can anyone tell me how I can find what file is assoicated to what exe, and return the fully qualified path to that exe??

Stuart
0
Comment
Question by:SJohnson
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1356869
You need to use the registry to do this.

Override TRegIniFile as follows:  (This allows you to open the registry at HKEY_CLASSES_ROOT and HKEY_LOCAL_MACHINE, not just HKEY_CURRENT_USER.

type
  TRegEx = class(TRegIniFile)
    constructor Create(TheRoot: HKey; TheFilename: string);
  end;

constructor TRegEx.Create(TheRoot: HKey; TheFilename: string);
begin
  inherited Create(TheFilename);
  CloseKey;
  RootKey := TheRoot;
  LazyWrite := True;
  OpenKey(TheFileName, True);
end;


Then, do the following:  (This example will be for *.txt files.)

var
  Filename: string;
  Reg: TRegEx;
begin
  Reg := TRegEx.Create(HKEY_CLASSES_ROOT, '');
  Filename := Reg.ReadString('.txt', '', '');
  if (Filename > '') then
    begin
      Filename := Reg.ReadString(Filename + '\shell\open\command', '', '');
      if (Filename > '') then
        ShowMessage(Filename);
    end;
  Reg.Free;
end;

This will return a string like "c:\windows\notepad.exe %1".  You will need to strip out the %1.

Regards,
JB
0
 
LVL 4

Expert Comment

by:d003303
ID: 1356870
Yo,

if you always have a physical file, you can use FindExecutable in the ShellAPI-unit. It returns the path to the application without any additional parameters.

Slash/d003303
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1356871
I would say that d003303's answer is better than mine, so reject my answer and award the points to d003303.  (You learn something new every day...  Thanks d003303.)

Using FindExecutable:

uses
  ShellApi, ...;

procedure GetExe;
var
  FindCode: Integer;
  Buf: array[0..MAX_PATH] of Char;
begin
  FillChar(Buf, SizeOf(Buf), 0);
  FindCode := FindExecutable('C:\My Documents\SomeFile.doc', 'C:\', @Buf);
  if (FindCode > 31) then
    ShowMessage(string(PChar(@Buf)));
end;

JB
0
 
LVL 1

Author Comment

by:SJohnson
ID: 1356872
Although Slash's repsonse was easier, it didnt seem to work as I needed.

JimBob - spot on.  Thats for that.  The points are yours.

Stuart

PS.  Nice to see people who arent bickering over the points!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 263
delphi exception 7 62
LAN or WAN ? 11 81
Firemonkey webbrowser scrollbars ? 1 29
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now