Board index » delphi » Calling windows prog

Calling windows prog

How do you call a windows program such as notepad  is there an equivalent to
the shell command in vb.

                        Thanks ,

                                        Richard.............

 

Re:Calling windows prog


WinExec('c:\windows\NotePad.exe',SW_SHOWNORMAL);

Re:Calling windows prog


  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

Rich <r...@madeup.com> wrote in article
<7a255l$6s...@news6.svr.pol.co.uk>...

Quote
> How do you call a windows program such as notepad  is there an equivalent
to
> the shell command in vb.

>                         Thanks ,

>                                         Richard.............

Other Threads