Solved

Associated EXE

Posted on 1998-01-15
4
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 136
Convert GUI app into console app for Win32 Env 5 138
shape, triangle, dbctrlgrid 3 47
migrate this code to work on android 1 46
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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