Board index » delphi » How ro use 'CreateProcess'-function

How ro use 'CreateProcess'-function

Hello !

I just want to launch applications using 'CreateProcess'-function. But....
I really don't understand those many parameters and how to use them.
I have heard that it isn't good idea to use 'WinExec'-function in Win95 or
NT.
(Why??? It's so simple....)

Please...Give me simple example .

-Weissu-

 

Re:How ro use 'CreateProcess'-function


On 29 Oct 1997 18:00:13 GMT, "Kimmo Weistr?m" <box12...@megabaud.fi>
wrote:

Quote
>Hello !

>I just want to launch applications using 'CreateProcess'-function. But....
>I really don't understand those many parameters and how to use them.
>I have heard that it isn't good idea to use 'WinExec'-function in Win95 or
>NT.
>(Why??? It's so simple....)

>Please...Give me simple example .

>-Weissu-

WinExec works fine if you just want to spawn another program and do
not care about keeping track of any aspect of it.  For example, if
your application is just a launcher that launches other apps, and you
use WinExec to launch Notepad, great.  It works fine for that.
        CreateProcess is more advanced in the following scenario...say
I want to uncompress a zip file, and then when the unzipping is done,
open a file that I know will be in the zip file.  With WinExec you
cannot tell when something is finished, so right after running the
unzipper, the next line of code which tries to utilize the file will
try to execute, and fail.  With createprocess you can keep track of
when the proc is finished and stuff like that...
        Now, I have to confess I have not used it in a while (haven't
used Delphi in a while), so I cannot help you with all the parameters,
but read the help...you will find that most of the params can be set
to nil or 0 anyway...
        ...and if your needs are simple and WinExec meets them, then
by all means keep using WinExec!  Have fun!

JoeK

Re:How ro use 'CreateProcess'-function


Quote
> I just want to launch applications using 'CreateProcess'-function. But....
> I really don't understand those many parameters and how to use them.
> I have heard that it isn't good idea to use 'WinExec'-function in Win95 or
> NT.
> (Why??? It's so simple....)

Micro$oft hast told not to support WinExec in future versions of there os, but
I think, they are forced in case of compatibly. Use WinExec if you like.

var
  StartupInfo                     : TStartupInfo;
  ProcessInfo                     : TProcessInformation;

begin
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  with StartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
  end;

  CreateProcess(nil,PChar('c:\dos\chkdsk.exe'), nil, nil,
False,NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
end;

Sven

Re:How ro use 'CreateProcess'-function


procedure DoSomething;
var   startupinfo  : TStartupInfo;
       processinfo: Tprocessinformation;
begin
fillchar(startupinfo,sizeof(startupinfo),0);
startupinfo.cb:=sizeof(startupinfo);
  if Createprocess(nil,'ApplicationToBeCalled
',nil,nil,false,NORMAL_PRIORITY_CLASS,
                           nil, ' DirectoryName',startupinfo,processinfo)
        then begin
                   WaitForSingleObject(Processinfo.hProcess,INFINITE);
                   Closehandle(Processinfo.hProcess);
               end;
end;

if  'ApplicationToBeCalled ' is text in for ex. Editbox you have to replace
  'ApplicationToBeCalled ' with Pchar(edit1.text)
if  ' DirectoryName' is text in for ex. Editbox you have to replace   '
DirectoryName ' with Pchar(edit2.text)
 WaitForSingleObject wait for the end of 'ApplicationToBeCalled' Instead of
INFINITE you can also define time
in ms until the process will be terminated

NORMAL_PRIORITY_CLASS could also replaced with
IDLE_PRIORITY_CLASS ,
HIGH_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS ( don`t use),

dj

det...@jost.pf.bawue.de

Kimmo Weistr?m <box12...@megabaud.fi> schrieb im Beitrag
<01bce49c$9f5c7900$9eb659c0@die-weissu-welt>...

Quote
> Hello !

> I just want to launch applications using 'CreateProcess'-function.
But....
> I really don't understand those many parameters and how to use them.
> I have heard that it isn't good idea to use 'WinExec'-function in Win95
or
> NT.
> (Why??? It's so simple....)

> Please...Give me simple example .

> -Weissu-

Re:How ro use 'CreateProcess'-function


procedure DoSomething;
var   startupinfo  : TStartupInfo;
       processinfo: Tprocessinformation;
begin
fillchar(startupinfo,sizeof(startupinfo),0);
startupinfo.cb:=sizeof(startupinfo);
  if Createprocess(nil,'ApplicationToBeCalled
',nil,nil,false,NORMAL_PRIORITY_CLASS,
                           nil, ' DirectoryName',startupinfo,processinfo)
        then begin
                   WaitForSingleObject(Processinfo.hProcess,INFINITE);
                   Closehandle(Processinfo.hProcess);
               end;
end;

if  'ApplicationToBeCalled ' is text in for ex. Editbox you have to replace
  'ApplicationToBeCalled ' with Pchar(edit1.text)
if  ' DirectoryName' is text in for ex. Editbox you have to replace   '
DirectoryName ' with Pchar(edit2.text)
 WaitForSingleObject wait for the end of 'ApplicationToBeCalled' Instead of
INFINITE you can also define time
in ms until the process will be terminated

NORMAL_PRIORITY_CLASS could also replaced with
IDLE_PRIORITY_CLASS ,
HIGH_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS ( don`t use),

Kimmo Weistr?m <box12...@megabaud.fi> schrieb im Beitrag
<01bce49c$9f5c7900$9eb659c0@die-weissu-welt>...

Quote
> Hello !

> I just want to launch applications using 'CreateProcess'-function.
But....
> I really don't understand those many parameters and how to use them.
> I have heard that it isn't good idea to use 'WinExec'-function in Win95
or
> NT.
> (Why??? It's so simple....)

> Please...Give me simple example .

> -Weissu-

Other Threads