Solved

Associated EXE

Posted on 1998-01-15
4
256 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

19 Experts available now in Live!

Get 1:1 Help Now