Solved

Running another executable but don't know path

Posted on 2000-05-03
5
200 Views
Last Modified: 2010-04-04
I need to run another exe from my delphi5 app. I have used the winexec and shellexecute, but what if I do not know the path of the executable. I am trying to run WordPerfect and pass it a macro name, but I do not want to hard code the path of WP install
0
Comment
Question by:jfreisen
[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
5 Comments
 
LVL 1

Expert Comment

by:Rheingold
ID: 2774367
Can't you just ask the user where WordPerfect is installed and save this path somewhere? Or you could look in the registry, in the part where the stuff is saved which program belongs to which filetype. Get the standard WordPerfect filetype extension and look which prog is default to open these kind of files. Then you have the path.

Regards
0
 
LVL 6

Expert Comment

by:edey
ID: 2774873
if the macro file name ext. is registered to wp, then "executing" the macro directly will cause windows to use wp to run the macro, just like attempting to run a .wpd file.

Gl
Mike
0
 

Expert Comment

by:skyrider_tieus
ID: 2774968
If you don't know where the another executable is, you might have to use an
exhaustive search in your drive to locate it.  
0
 

Accepted Solution

by:
skyrider_tieus earned 50 total points
ID: 2775430
Here is some code snippet to use.  Hope this is the answer to your question.

unit frmMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    FfileName : String;
    function GetDirectoryName(Dir: String): String;
    procedure FindFile(APath: String; FileName: String);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.GetDirectoryName(Dir: String): String;
begin
  if Dir[Length(Dir)]<> '\' then
    Result := Dir+'\'
  else
    Result := Dir;
end;

procedure TForm1.FindFile(APath: String; FileName: String);
var
  FSearchRec,
  DSearchRec: TSearchRec;
  FindResult: integer;

  function IsDirNotation(ADirName: String): Boolean;
  begin
    Result := (ADirName = '.') or (ADirName = '..');
  end;

begin

  APath := GetDirectoryName(APath); // Obtain a valid directory name
  // Find the first occurence of the specified file name
  FindResult := FindFirst(APath+FileName,faAnyFile+faHidden+
                          faSysFile+faReadOnly,FSearchRec);
  try
   //  Continue to search for the file

    If FindResult = 0 then
    begin
        Label1.Caption := APath+FileName;
        exit;
    end;
 
    FindResult := FindFirst(APath+'*.*', faDirectory, DSearchRec);

    while FindResult = 0 do
    begin
      if ((DSearchRec.Attr and faDirectory) = faDirectory) and not
         IsDirNotation(DSearchRec.Name) then
         FindFile(APath+DSearchRec.Name, FileName); // Recursion here

      FindResult := FindNext(DSearchRec);
    end;  // while
  finally
    FindClose(FSearchRec);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    findfile('C:', 'wsock32.dll');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Close;
end;

end.
0
 
LVL 1

Expert Comment

by:duke_n
ID: 2928447
you should access the registry.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths

here you search for the key with your app's exename.

if you want I will write you some code.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 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