Solved

Running another executable but don't know path

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML text in the body of an email (delphi code) 12 120
Multiple image collision 13 75
Performance of SQL statement 37 112
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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