Solved

Associated EXE

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

623 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