Discussion:
關於CreateProcess()的用法
(时间太久无法回复)
Vannes
2007-05-03 06:39:00 UTC
Permalink
小弟使用CreateProcess()去開啟一個InstallShield 安裝程式, 該安裝程式在硬碟中只有一個process; 但在光碟中,
程式本身會將自己copy到硬碟中並開啟一個新的process執行. 小弟的成是需要等待整個安裝完成後在進行下一步, 然而這情況卻無法等下去了??
請問有甚麼解決的方法嗎? 小弟曾經試過將 bInheritHandles設為true, 但似乎還是不行...以下附上程式碼請各位高手解答, 謝謝!

//CreateProcess fuction variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwExit;
TCHAR szdrvInstX64[MAX_PATH];

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wsprintf(szdrvInstX64, "%s%s", szCurModPath, ITEM2SETUPPATH);
if( !CreateProcess( NULL, szdrvInstX64, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi) )
{
::AfxMessageBox("CreateProcess() failed!");
return;
}
//Set itself to bottom.
::ShowWindow(hWndMain, SW_MINIMIZE);

WaitForSingleObject( pi.hProcess, INFINITE ); // Wait until child process
exits.
GetExitCodeProcess(pi.hProcess, &dwExit);

CloseHandle( pi.hProcess ); // Close process and thread handles.
CloseHandle( pi.hThread );

::ShowWindow(hWndMain, SW_RESTORE);
璉璉
2007-05-07 00:49:01 UTC
Permalink
«Øij§A§â ProcessId ¿é¥X¡A€ñžû·í®ÉŠb€u§@ºÞ²z­û€ºªºµ{§Ç¡A§ÚŠb·Q¡A€£ªŸ¹D·|€£·|¬O InstallShield ·|©I¥s¥t€@­ÓŠwžËµ{Š¡¡H
€ñŠp»¡ setup.exe ©I¥s setup1.exe «á¡AŠÛ€vŽNÃö³¬¡AŠÓ§Aµ¥ªº¬O setup.exe ¡AŽN»{¬°µ²§ô€F¡C
©ó news:72D3C3A1-E0E5-4FC2-B363-F33CFD80D9A4%40microsoft.com µoªí
œÐ°ÝŠ³¬Æ»òžÑšMªº€èªk¶Ü? €p§ÌŽ¿žgžÕ¹L±N bInheritHandles³]¬°true, ŠýŠü¥GÁÙ¬O€£Šæ...¥H€Uªþ€Wµ{Š¡œXœÐŠUŠì°ª€âžÑµª, ÁÂÁÂ!
//CreateProcess fuction variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwExit;
TCHAR szdrvInstX64[MAX_PATH];
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wsprintf(szdrvInstX64, "%s%s", szCurModPath, ITEM2SETUPPATH);
if( !CreateProcess( NULL, szdrvInstX64, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi) )
{
::AfxMessageBox("CreateProcess() failed!");
return;
}
//Set itself to bottom.
::ShowWindow(hWndMain, SW_MINIMIZE);
WaitForSingleObject( pi.hProcess, INFINITE ); // Wait until child process
exits.
GetExitCodeProcess(pi.hProcess, &dwExit);
CloseHandle( pi.hProcess ); // Close process and thread handles.
CloseHandle( pi.hThread );
::ShowWindow(hWndMain, SW_RESTORE);
--
­·¬ê¬ì§ÞÅçÃÒŠ³­­€œ¥q ASP.NET Web News Reader 0.2.6 UTF-8 Beta
ºô¯žŠa¹Ï http://tlcheng.twbbs.org/wwwmap.htm
¬y°ìšŸ¬x/°Ï°ì€ôžê·œ/®}ª@ºô/ªŽºÀ¹Ï/»y­µ³q°T €å³¹»Pµ{Š¡
Basic/Fortran/Windows API/.Net/»²§U»¡©úÀÉ ­ì©lœX¡B€å³¹»P°Qœ×
·L³nµ{Š¡³]­p¡Bšt²ÎºÞ²zšÏ¥Î·s§Þ³Nœ×ŸÂ°Qœ×°Ï¡Aºô€ÍŠ^ÂЫá§Y®É²°T¡B¹q€l¶l¥ó³qªŸ¡G
MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.vsnet
Vannes
2007-05-07 05:18:00 UTC
Permalink
謝謝璉璉.
的確是這個樣子的, 一開始他會自行結束並產生另一個process. 所以我的監控會失敗 :(
在InstallShield官方網站提到, 這個情況可以用"指定"processID 解決, 但我只能指定我所產生的process,
我如何得知下一個ProcessID病去監控它呢?

"璉璉" 來函:
建議你把 ProcessId 輸出,比較當時在工作管理員內的程序,我在想,不知道會不會是 InstallShield 會呼叫另一個安裝程式?
比如說 setup.exe 呼叫 setup1.exe 後,自己就關閉,而你等的是 setup.exe ,就認為結束了。
於 news:72D3C3A1-E0E5-4FC2-B363-F33CFD80D9A4%40microsoft.com 發表
小弟使用CreateProcess()去開啟一個InstallShield 安裝程式, 該安裝程式在硬碟中只有一個process; 但在光碟中,
程式本身會將自己copy到硬碟中並開啟一個新的process執行. 小弟的成是需要等待整個安裝完成後在進行下一步, 然而這情況卻無法等下去了??
請問有甚麼解決的方法嗎? 小弟曾經試過將 bInheritHandles設為true, 但似乎還是不行...以下附上程式碼請各位高手解答, 謝謝!
//CreateProcess fuction variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwExit;
TCHAR szdrvInstX64[MAX_PATH];
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wsprintf(szdrvInstX64, "%s%s", szCurModPath, ITEM2SETUPPATH);
if( !CreateProcess( NULL, szdrvInstX64, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi) )
{
::AfxMessageBox("CreateProcess() failed!");
return;
}
//Set itself to bottom.
::ShowWindow(hWndMain, SW_MINIMIZE);
WaitForSingleObject( pi.hProcess, INFINITE ); // Wait until child process
exits.
GetExitCodeProcess(pi.hProcess, &dwExit);
CloseHandle( pi.hProcess ); // Close process and thread handles.
CloseHandle( pi.hThread );
::ShowWindow(hWndMain, SW_RESTORE);
--
風禹科技驗證有限公司 ASP.NET Web News Reader 0.2.6 UTF-8 Beta
網站地圖 http://tlcheng.twbbs.org/wwwmap.htm
流域防洪/區域水資源/徐昇網/玫瑰圖/語音通訊 文章與程式
Basic/Fortran/Windows API/.Net/輔助說明檔 原始碼、文章與討論
微軟程式設計、系統管理使用新技術論壇討論區,網友回覆後即時簡訊、電子郵件通知:
MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.vsnet
璉璉
2007-05-08 01:32:07 UTC
Permalink
ŠpªG©x€èºô¯žŠ³Ž£šì¡AÀ³žÓ·|Š³©x€èžÑšM€è®×¥i°ÑŠÒ¡A€ñŠp»¡šÏ¥Î©R¥OŠCšÓ³B²z¡A±±šî§Oªº³nÅé²£¥Í«ü©wªº PID §Úı±o€£€Ó¥i¯à¡C
©ó news:789A93A7-CB1F-47BB-884E-01A6E9883EA2%40microsoft.com µoªí
ÁÂÁÂæ£æ£.
ŠbInstallShield©x€èºô¯žŽ£šì, ³o­Ó±¡ªp¥i¥H¥Î"«ü©w"processID žÑšM, Šý§Ú¥u¯à«ü©w§Ú©Ò²£¥Íªºprocess,
"æ£æ£" šÓšç¡G
Post by 璉璉
€ñŠp»¡ setup.exe ©I¥s setup1.exe «á¡AŠÛ€vŽNÃö³¬¡AŠÓ§Aµ¥ªº¬O setup.exe ¡AŽN»{¬°µ²§ô€F¡C
©ó news:72D3C3A1-E0E5-4FC2-B363-F33CFD80D9A4%40microsoft.com µoªí
œÐ°ÝŠ³¬Æ»òžÑšMªº€èªk¶Ü? €p§ÌŽ¿žgžÕ¹L±N bInheritHandles³]¬°true, ŠýŠü¥GÁÙ¬O€£Šæ...¥H€Uªþ€Wµ{Š¡œXœÐŠUŠì°ª€âžÑµª, ÁÂÁÂ!
//CreateProcess fuction variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD dwExit;
TCHAR szdrvInstX64[MAX_PATH];
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wsprintf(szdrvInstX64, "%s%s", szCurModPath, ITEM2SETUPPATH);
if( !CreateProcess( NULL, szdrvInstX64, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi) )
{
::AfxMessageBox("CreateProcess() failed!");
return;
}
//Set itself to bottom.
::ShowWindow(hWndMain, SW_MINIMIZE);
WaitForSingleObject( pi.hProcess, INFINITE ); // Wait until child process
exits.
GetExitCodeProcess(pi.hProcess, &dwExit);
CloseHandle( pi.hProcess ); // Close process and thread handles.
CloseHandle( pi.hThread );
::ShowWindow(hWndMain, SW_RESTORE);
--
­·¬ê¬ì§ÞÅçÃÒŠ³­­€œ¥q ASP.NET Web News Reader 0.2.6 UTF-8 Beta
ºô¯žŠa¹Ï http://tlcheng.twbbs.org/wwwmap.htm
¬y°ìšŸ¬x/°Ï°ì€ôžê·œ/®}ª@ºô/ªŽºÀ¹Ï/»y­µ³q°T €å³¹»Pµ{Š¡
Basic/Fortran/Windows API/.Net/»²§U»¡©úÀÉ ­ì©lœX¡B€å³¹»P°Qœ×
·L³nµ{Š¡³]­p¡Bšt²ÎºÞ²zšÏ¥Î·s§Þ³Nœ×ŸÂ°Qœ×°Ï¡Aºô€ÍŠ^ÂЫá§Y®É²°T¡B¹q€l¶l¥ó³qªŸ¡G
MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.vsnet
Loading...