Solved

Associated EXE

Posted on 1998-01-15
4
263 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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
Delphi Spellcheck in Webbrowser 1 45
Delphi 2 77
How to renew a Delphi rad-studio licence? 5 75
how to send memory stream from ics Client To ics server ? 11 175
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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