Board index » delphi » Menu object : how to execute EXE file that is NOT part of given DEL Project

Menu object : how to execute EXE file that is NOT part of given DEL Project

How do you run (execute) a <file>.EXE that is NOT part of the project
that
contains the given menu object ??
i.e. click menu item in <projectTest> and execute a <file>.EXE where
<file>.EXE is <projectSample>.EXE

thanks

 

Re:Menu object : how to execute EXE file that is NOT part of given DEL Project


Hi Kenneth!

You might find the following code useful:

function CmdLineExecAsync(const CmdLine: string): THandle;
var
  SInfo: TStartupInfo;
  PRocInfo: TProcessInformation;
begin

  FillChar(SInfo,SizeOf(SInfo),0);
  SInfo.cb := SizeOf(SInfo);

  if CreateProcess(
    nil,
    PChar(CmdLine),
    nil,
    nil,
    BOOL(true),
    0,
    nil,
    nil,
    SInfo,
    ProcInfo
  ) <> BOOL(0)
  then
  begin
    CloseHandle(ProcInfo.hThread);
    result := ProcInfo.hProcess
  end
  else
    raise Exception.Create('CmdLineExecAsync() Error creating proccess for
command line: ' + CmdLine)

end;

procedure CmdLineExecSync(const CmdLine: string);
var
  PH: THandle;
begin

  PH := CmdLineExecAsync(CmdLine);

  if WaitForSingleObject(PH,INFINITE) = WAIT_FAILED then
    raise Exception.Create('CmdLineExecSync() Error waiting process to
terminate.');
  CloseHandle(PH);
end;

--
Branko Dimitrijevic
brank...@eunet.yu
http://bepp.8m.com

Quote
kenneth thompson <kenneth.l.thomp...@worldnet.att.net> wrote in message

news:385D1A51.53162993@worldnet.att.net...
Quote
> How do you run (execute) a <file>.EXE that is NOT part of the project
> that
> contains the given menu object ??
> i.e. click menu item in <projectTest> and execute a <file>.EXE where
> <file>.EXE is <projectSample>.EXE

> thanks

Re:Menu object : how to execute EXE file that is NOT part of given DEL Project


Use WinExec(), ShellExecute() (in ShellAPI unit), or CreateProcess().

--
Thanks,
Jon.

Quote
"kenneth thompson" <kenneth.l.thomp...@worldnet.att.net> wrote in message

news:385D1A51.53162993@worldnet.att.net...
Quote
> How do you run (execute) a <file>.EXE that is NOT part of the project
> that
> contains the given menu object ??
> i.e. click menu item in <projectTest> and execute a <file>.EXE where
> <file>.EXE is <projectSample>.EXE

> thanks

Re:Menu object : how to execute EXE file that is NOT part of given DEL Project


Using SHELLAPI  works just like i want .. thanks for the tip...
Quote
"Jon E. Scott" wrote:
> Use WinExec(), ShellExecute() (in ShellAPI unit), or CreateProcess().

> --
> Thanks,
> Jon.

> "kenneth thompson" <kenneth.l.thomp...@worldnet.att.net> wrote in message
> news:385D1A51.53162993@worldnet.att.net...
> > How do you run (execute) a <file>.EXE that is NOT part of the project
> > that
> > contains the given menu object ??
> > i.e. click menu item in <projectTest> and execute a <file>.EXE where
> > <file>.EXE is <projectSample>.EXE

> > thanks

Other Threads