2012-06-05 55 views
10

如何獲取由shellexecute函數調用的exe的返回值。如何獲取由ShellExecute調用的exe的返回值

ShellExecute(NULL, NULL, TEXT (".\\dpinstx86.exe"), NULL, NULL, SW_SHOWNORMAL); 

在上面的例子中,我想要「dpinstx86.exe」的返回值。

+1

我覺得你「返回值」的意思是從CMD的輸出,這個問題地址:http://stackoverflow.com/questions/469152/using-shellexecuteex-and-capturing-standard-in退房手續,ERR。 – Ben

回答

19

改用ShellExecuteEx來取得進程句柄,而GetExitCodeProcess得到退出碼。

SHELLEXECUTEINFO ShExecInfo = {0}; 
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); 
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; 
ShExecInfo.hwnd = NULL; 
ShExecInfo.lpVerb = NULL; 
ShExecInfo.lpFile = "c:\\MyProgram.exe";   
ShExecInfo.lpParameters = ""; 
ShExecInfo.lpDirectory = NULL; 
ShExecInfo.nShow = SW_SHOW; 
ShExecInfo.hInstApp = NULL; 
ShellExecuteEx(&ShExecInfo); 
WaitForSingleObject(ShExecInfo.hProcess,INFINITE); 
+1

不要忘記在手柄上等待*。 –

+0

任何示例都會很棒... – 2vision2

+1

http://www.codeproject.com/Articles/1842/A-newbie-s-elementary-guide-to-spawning-processes ...並用hProcess調用GetExitCodeProcess() SHELLEXECUTEINFO的成員。 – kol

相關問題