Board index » delphi » Exec DOS prog from Delphi prog

Exec DOS prog from Delphi prog

Hi

Recently, I asked how to execute a DOS prog from a Delphi application; I
received many answers, thankyou all. Somebody sent me this example:

procedure RunAProgram(aFile: string; How2Show: Word);
var
  pi: TProcessInformation;
  si: TStartupInfo;
begin
  FillMemory(@si, sizeof(si), 0 );
  si.cb := sizeof(si);
  ChDir(ExtractFilePath(aFile));
  CreateProcess(nil, PChar(aFile), Nil, Nil, False,
NORMAL_PRIORITY_CLASS,  Nil, Nil, si, pi );
  ChDir(ExtractFilePath(ParamStr(0)));
  CloseHandle( pi.hProcess );
  CloseHandle( pi.hThread );
end;

This is the one I used because it also shows how to change directories
which is just what I needed; it works fine as long as both the DOS prog
and the Delphi prog are on local drives. On my computer, the Delphi prog
is in C:\WORK\WINPROGS\ and the DOS prog is in D:\TEST\ and the above
example works fine.

It does not work tough on a network drive; the Delphi prog is in
L:\WINAPPS\ and the DOS prog is in L:\DOSAPPS\. The L drive is a Novell
mapped drive; it is mapped as root altough it is not really in the root,
I don't know if that is important.

I use Win 95 and Delphi 2 in french and I know you'd like to know what
the error message is. So here is the best translation I can come up
with:

"Unable to find the working directory for this program. The program may
not be able to find its files and documents. Verify that the working
directory is correctly specified in the properties. Do you wish to run
the program anyway ?"

Cliking Yes to this question does start the program but it does not (as
expected I supposed) find its files and documents; now I know that the
directory is correctly specified because the program and its file are in
the same directory. Also, it works fine on a local drive, even across
different drives as long as they are local.

What can be wrong ?

Thanks

Pat

 

Re:Exec DOS prog from Delphi prog


The 8th parameter which you are setting to nil is the program's
directory, you should probably set this is running from a network
drive. This can be done with the following alteration...

var
  sDirectory: string;
...
begin
...
sDirectory := ExtractFilePath(aFile);
CreateProcess(nil, PChar(aFile), Nil, Nil, False,
 NORMAL_PRIORITY_CLASS,  Nil, PChar(sDirectory), si, pi );
...
end;

In article <37E014EC.6471C...@citenet.net>,
  Patrice Gambaro <gamb...@citenet.net> wrote:

Quote
> Hi

> Recently, I asked how to execute a DOS prog from a Delphi
application; I
> received many answers, thankyou all. Somebody sent me this example:

> procedure RunAProgram(aFile: string; How2Show: Word);
> var
>   pi: TProcessInformation;
>   si: TStartupInfo;
> begin
>   FillMemory(@si, sizeof(si), 0 );
>   si.cb := sizeof(si);
>   ChDir(ExtractFilePath(aFile));
>   CreateProcess(nil, PChar(aFile), Nil, Nil, False,
> NORMAL_PRIORITY_CLASS,  Nil, Nil, si, pi );
>   ChDir(ExtractFilePath(ParamStr(0)));
>   CloseHandle( pi.hProcess );
>   CloseHandle( pi.hThread );
> end;

> This is the one I used because it also shows how to change directories
> which is just what I needed; it works fine as long as both the DOS
prog
> and the Delphi prog are on local drives. On my computer, the Delphi
prog
> is in C:\WORK\WINPROGS\ and the DOS prog is in D:\TEST\ and the above
> example works fine.

> It does not work tough on a network drive; the Delphi prog is in
> L:\WINAPPS\ and the DOS prog is in L:\DOSAPPS\. The L drive is a
Novell
> mapped drive; it is mapped as root altough it is not really in the
root,
> I don't know if that is important.

> I use Win 95 and Delphi 2 in french and I know you'd like to know what
> the error message is. So here is the best translation I can come up
> with:

> "Unable to find the working directory for this program. The program
may
> not be able to find its files and documents. Verify that the working
> directory is correctly specified in the properties. Do you wish to run
> the program anyway ?"

> Cliking Yes to this question does start the program but it does not
(as
> expected I supposed) find its files and documents; now I know that the
> directory is correctly specified because the program and its file are
in
> the same directory. Also, it works fine on a local drive, even across
> different drives as long as they are local.

> What can be wrong ?

> Thanks

> Pat

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Other Threads