[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Running another executable but don't know path

Posted on 2000-05-03
5
Medium Priority
?
203 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 100 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 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