Solved

Running another executable but don't know path

Posted on 2000-05-03
5
188 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

16 Experts available now in Live!

Get 1:1 Help Now