bool CCreateProcessDlg::ProcessExec(LPCTSTR fileName) { if(!CreateProcess(fileName,NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,NULL,NULL,NULL,&processInfo)) { return FALSE; } //CloseHandle(processInfo.hThread); //CloseHandle(processInfo.hProcess); return TRUE; } void CCreateProcessDlg::OnBnClickedButtonExec() { // TODO: Add your control notification handler code here ProcessExec(_T("iesample")); } void CCreateProcessDlg::OnBnClickedButtonExit() { // TODO: Add your control notification handler code here DWORD exitCode; //ExitProcess(exitCode); if(TerminateProcess(processInfo.hProcess,exitCode)) { MessageBox(_T("exit iesample.exe success")); if(ExitProcess(exitCode)) { MessageBox(_T("exit CreateProcess.exe success")); } else { MessageBox(_T("exit CreateProcess.exe success")); } } else { MessageBox(_T("exit iesample.exe fail")); } }