一個正執行的程式如何啟動另一新程式並關閉現執行程式

fengbingchun發表於2010-05-31

最簡單的方法有兩個函式即可實現:

 

//啟動新程式
WinExec("存放另一新程式的路徑", SW_SHOW);
//關閉現執行軟體

 ExitThread(0);

 

 

若在win ce 下,用WinExec這個函式就不對了,那時就應該用ShellExecuteEx了。

 SHELLEXECUTEINFO ShExecInfo;

 ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
 ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
 ShExecInfo.hwnd = NULL;
 ShExecInfo.lpVerb = NULL;
 ShExecInfo.lpFile = _T("//Program Files//Amtps//Amtps.exe");
 ShExecInfo.lpParameters = _T("");
 ShExecInfo.lpDirectory = NULL;
 ShExecInfo.nShow = SW_SHOW;
 ShExecInfo.hInstApp = NULL;

 ShellExecuteEx(&ShExecInfo);

相關文章