使用CreateProcess()函数0 c6 y: g8 ]7 U( z8 A, i
! B% y3 s' M$ N$ p+ {& S" [
以下是一个使用CreateProcess()函数的例子:
( J+ ?' A- J7 |6 Qvoid CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) & \8 I( V; x# f7 B. r/ e
{
4 W& ~' n& V/ V5 I8 S, ^PROCESS_INFORMATION piProcInfo;
2 E G ?& |3 T6 q _- q7 XSTARTUPINFO siStartInfo;
. [* p. J, l6 h& c( [( }// Set up members of STARTUPINFO structure., l3 H* h4 y% v- O
siStartInfo.cb = sizeof(STARTUPINFO); + t; u; Z. Z9 ~# B2 i, @& z& f
siStartInfo.lpReserved = NULL;
: z4 z8 P* M( \! R+ h) JsiStartInfo.lpReserved2 = NULL;
, D6 Y) G$ D- y ?( x( zsiStartInfo.cbReserved2 = 0;) ~$ @' k8 e" ~+ c. \0 y
siStartInfo.lpDesktop = NULL; 2 A$ ^6 L& C9 G* O
siStartInfo.dwFlags = 0;
2 N" ]: R4 W' \
* M F! I0 P" f, O$ Q4 E// Create the child process.
: }7 s+ i' c# PCreateProcess( ( A9 t4 b% ]+ x
NULL,
. U7 w9 ~$ q5 nstrCmdLine.c_str(),
Z" a* j+ t1 U! ~& TNULL, // process security attributes
+ i+ t4 Q& S" |8 ENULL, // primary thread security attributes
0 }$ \5 D2 }. S! ?- J. q0, // handles are inherited
# {# _; M9 X, t$ ^) `! I+ t0, // creation flags3 l: q; c w, h. [
NULL, // use parent's environment
* E+ _3 z2 [3 \ R' q L z5 ~NULL, // use parent's current directory) V; Q8 s& t& _4 @2 `2 r
&siStartInfo, // STARTUPINFO pointer! V7 D! [2 N& T
&piProcInfo); // receives PROCESS_INFORMATION
- s5 G1 q) v i: ]$ O/ c$ e// Wait for the processs to finish
# f- ~& k6 t) ]1 f" D4 u0 _DWORD rc = WaitForSingleObject(
! F' n. y p; A+ [piProcInfo.hProcess, // process handle
8 Y. K7 t9 ?) G0 u8 F( o/ \ D$ k5 }INFINITE);
) r* t* [5 }, b! y4 Z}
2 e7 G, q5 a" @( b2 t* Z4 }0 ]/ |9 v
3 x/ ]5 l( k% e/ i8 \ |