Solved

Running another executable but don't know path

Posted on 2000-05-03
5
183 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

12 Experts available now in Live!

Get 1:1 Help Now