|
使用CreateProcess()函数3 s; A6 b4 { i0 m- C
* p$ ?0 e4 s5 H; a; H 以下是一个使用CreateProcess()函数的例子:
]5 p ?3 g& kvoid CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine)
2 a# h/ Y: p- q6 _9 o1 O# z8 J{ 2 e* D3 \! L9 D6 C
PROCESS_INFORMATION piProcInfo; 9 e/ o" F1 w1 u, h
STARTUPINFO siStartInfo;
2 \& o! W: F' ?; q5 z9 }- n0 _// Set up members of STARTUPINFO structure.# A2 l1 x. u. o+ u8 B8 T
siStartInfo.cb = sizeof(STARTUPINFO); 9 P$ O& n% y4 f# h1 T, J
siStartInfo.lpReserved = NULL; j% ?1 x* c: ^5 d _' w+ H0 j
siStartInfo.lpReserved2 = NULL; / b$ U" c. Y7 x6 W {' k
siStartInfo.cbReserved2 = 0;
* s4 w/ ?$ H. i+ F4 v1 [, V" nsiStartInfo.lpDesktop = NULL;
$ G$ F! u( n# L. J' S1 XsiStartInfo.dwFlags = 0;
- i5 L( J7 e9 c6 R
$ S; V7 d/ m0 r# B" T, L// Create the child process.7 k, N/ ?) H- y; s: n3 @
CreateProcess(
. e$ n; L3 w8 J+ s* |, RNULL,2 _ l: O8 v- g2 Z- C9 q3 a! y
strCmdLine.c_str(),
" _2 H" O0 a; u) P4 E% s8 |- eNULL, // process security attributes
, g4 G+ P- f/ s" p7 FNULL, // primary thread security attributes
* F& I/ |9 l! D6 _+ B" z0, // handles are inherited2 t) d7 @( f5 C# X+ _. O- H# {/ m
0, // creation flags
6 K& K1 w/ }9 O% Z! h$ [3 LNULL, // use parent's environment+ N$ ~+ m$ f( l
NULL, // use parent's current directory
8 @4 E' G: o; K5 R&siStartInfo, // STARTUPINFO pointer
! [4 V4 k8 o! ]&piProcInfo); // receives PROCESS_INFORMATION 1 T" n4 `4 L2 O3 }. a* D6 H9 U" z
// Wait for the processs to finish4 P. b- A! E% G( k9 M+ l
DWORD rc = WaitForSingleObject(9 p. \0 q2 N2 B, G: h
piProcInfo.hProcess, // process handle3 B; Q3 A: Q- D ]
INFINITE); 7 R8 `0 t' H* f1 n
}% w7 f# j/ s; g% U, g* [2 `/ A
6 y: K- R$ M" E9 N, f: z t
|