代码如下:
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo; CreateProcess(
NULL,
"c:\\program files\\tencent\\qq\\coralqq.exe",
NULL, // process security attributes
NULL, // primary thread security attributes
NORMAL_PRIORITY_CLASS, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION应该没有问题啊?
另外我用
ShellExecute(NULL, NULL,
"c:\\program files\\tencent\\qq\\coralqq.exe",
NULL, NULL, SW_SHOW);
却可以成功!
但是 将"c:\\program files\\tencent\\qq\\coralqq.exe"
换成"c:\program files\tencent\qq\\coralqq.exe"就不行了?
这是为什么呢??
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo; CreateProcess(
NULL,
"c:\\program files\\tencent\\qq\\coralqq.exe",
NULL, // process security attributes
NULL, // primary thread security attributes
NORMAL_PRIORITY_CLASS, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION应该没有问题啊?
另外我用
ShellExecute(NULL, NULL,
"c:\\program files\\tencent\\qq\\coralqq.exe",
NULL, NULL, SW_SHOW);
却可以成功!
但是 将"c:\\program files\\tencent\\qq\\coralqq.exe"
换成"c:\program files\tencent\qq\\coralqq.exe"就不行了?
这是为什么呢??
CreateProcess(
NULL,
"\"c:\\program files\\tencent\\qq\\coralqq.exe\",
NULL, // process security attributes
NULL, // primary thread security attributes
NORMAL_PRIORITY_CLASS, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;CreateProcess(
NULL,
"\"c:\\program files\\tencent\\qq\\coralqq.exe\",
NULL, // process security attributes
NULL, // primary thread security attributes
NORMAL_PRIORITY_CLASS, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
请高手们再指点一下,最好能给个例子呀,谢谢!!!
{
STARTUPINFO si;
PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"MyChildProcess", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
ErrorExit( "CreateProcess failed." );
} // Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
这是msdn上的例子
"\"c:\\program files\\tencent\\qq\\coralqq.exe\",这样写是不对的,应该是
"c:\\program files\\tencent\\qq\\coralqq.exe"
是该如楼上的所说,加上一句 si.cb = sizeof(si);
STARTUPINFO.cb是说明结构的大小。
微软在结构中加这个字段,估计是为了以后扩展着想。
当改变 startupinfo 的定义时,可以根据这个成员的值判别是哪个版本。