Board index » delphi » Execute command line - urgent

Execute command line - urgent

I want to execute some program from my Delphi application, with
something like :
                        Execute('c:\windows\Notepad.exe');

but I can't find the good syntax under Delphi2.0 . Could You Help me ?
(please)

        Niko

 

Re:Execute command line - urgent


Niko,
  Take a look at the following.  It uses the ExecuteFile() function that
can be found in the FMXUtils.pas file that came in the Demos\Doc\Filemanex
directory with Delphi 1.0 and 2.0.  (As far as I know it should also be in
D3) ExecuteFile() is basically just a wrapper for the ShellExecute()
function so this shows how to convert the params from pascal for use with
it.

implementation

{$R *.DFM}

uses
  ShellAPI;

function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..79] of Char;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;

To use it do something like:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExecuteFile('C:\WINDOWS\NOTEPAD.EXE','','',SW_SHOW);
end;

This will fire up the the Notepad.  Or:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExecuteFile('C:\WINDOWS\NOTEPAD.EXE','C:\Myfiles\test.txt','',SW_SHOW);
end;

This will fire up the the Notepad and pass it the command line parameter
C:\Myfiles\test.txt which it will open.

Hope this helps!
--

Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Nicolas RENAUDIN <renau...@ec-lille.fr> wrote in article
<354BA84A.7D600...@ec-lille.fr>...

Quote
> I want to execute some program from my Delphi application, with
> something like :
>                    Execute('c:\windows\Notepad.exe');

> but I can't find the good syntax under Delphi2.0 . Could You Help me ?
> (please)

>    Niko

Re:Execute command line - urgent


Try to use Winexec('c:\windows\Notepad.exe'); or
ShellExecute('c:\windows\Notepad.exe','open',...);
try help on shell execute, I dont remember all the parameters but it is
very easy to use.

Quote
Nicolas RENAUDIN wrote:
> I want to execute some program from my Delphi application, with
> something like :
>                         Execute('c:\windows\Notepad.exe');

> but I can't find the good syntax under Delphi2.0 . Could You Help me ?
> (please)

>         Niko

Re:Execute command line - urgent


Try to use Winexec('c:\windows\Notepad.exe'); or
ShellExecute('c:\windows\Notepad.exe','open',...);
try help on shell execute, I dont remember all the parameters but it is
very easy to use.
                                    Jean-Pascal Lachapelle
                                                wizardbi...@geocities.com

Quote
Nicolas RENAUDIN wrote:
> I want to execute some program from my Delphi application, with
> something like :
>                         Execute('c:\windows\Notepad.exe');

> but I can't find the good syntax under Delphi2.0 . Could You Help me ?
> (please)

>         Niko

Re:Execute command line - urgent


On Sun, 03 May 1998 01:12:10 +0200, Nicolas RENAUDIN

Quote
<renau...@ec-lille.fr> wrote:
>I want to execute some program from my Delphi application, with
>something like :
>                    Execute('c:\windows\Notepad.exe');

>but I can't find the good syntax under Delphi2.0 . Could You Help me ?
>(please)

>    Niko

Try

var
your_string : String;

begin
 your_string := 'c:\windows\notepad.exe';

 WinExec( PChar ( your_string ) , SH_SHOW);
end;

David.

Re:Execute command line - urgent


  No, no, no+ACE-  Do not use WinExec in a 32bit application+ACE-  You use
CreateProcess (read the help file)

--
Jason Wallace
SL Software
DarkElf+AEA-SLSoftware.reno.nv.us
--
+ACI-We are Microsoft.  Resistance is Futile.  You will be Assimiliated.+ACI-

Quote
David van Swam wrote in message +ADw-354cdbde.596910+AEA-news.molyvos.net+AD4-...

+AD4-On Sun, 03 May 1998 01:12:10 +020-, Nicolas RENAUDIN
Quote
+AD4APA-renaudin+AEA-ec-lille.fr+AD4- wrote:

+AD4-
+AD4APg-I want to execute some program from my Delphi application, with
+AD4APg-something like :
+AD4APg- Execute('c:+AFw-windows+AFw-Notepad.exe')+ADs-
+AD4APg-
+AD4APg-but I can't find the good syntax under Delphi2.0 . Could You Help me ?
+AD4APg-(please)
+AD4APg-
+AD4APg- Niko
+AD4-Try
+AD4-
+AD4-var
+AD4-your+AF8-string : String+ADs-
+AD4-
+AD4-
+AD4-begin
+AD4- your+AF8-string :+AD0- 'c:+AFw-windows+AFw-notepad.exe'+ADs-
+AD4-
+AD4- WinExec( PChar ( your+AF8-string ) , SH+AF8-SHOW)+ADs-
+AD4-end+ADs-
+AD4-
+AD4-
+AD4-David.
+AD4-

Other Threads