|
发表于 2013-4-28 17:51:36
|
显示全部楼层
- #include <windows.h>
- void main( void ) {
- 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).
- "C:\\WINDOWS\\system32\\calc.exe", // 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.
- )
- {
- exit(-1);
- }
- printf("Process hadle is :%x\n",pi.hProcess);
- printf("Process ID is :%x\n",pi.dwProcessId);
- // Wait until child process exits.
- WaitForSingleObject( pi.hProcess, INFINITE );
- // Close process and thread handles.
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
复制代码 我机子上的计算器程序在"C:\\WINDOWS\\system32\\calc.exe"若要打开其它程序可对这个参数做相应修改. |
|