使用ShellExecuteEX取得所叫用應用程式的ProcessID |
尚未結案
|
blue
中階會員 ![]() ![]() ![]() 發表:170 回覆:136 積分:81 註冊:2002-04-15 發送簡訊給我 |
Hi,各位先進大家好:
小弟遇到一個奇怪問題不知該如何解決, 小弟希望開啟使用者所選定的文件(可能是Word, Excel....不定) 使用 ShellExecuteEX啟動文件後希望取得該程式的ProcessID, 程式如后附, 但,問題來了,以下的程式所取的是這支程式的ProssID,不是關聯到文件的那個程式的ID, 若是將 Explorer.exe 改為 Winword.exe(假設Tempfile是一個Word文件),則可以正常取得Winword的ProcessID, 謝謝! FillChar(SEInfo, SizeOf(SEInfo), 0) ; SEInfo.cbSize := SizeOf(TShellExecuteInfo); SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS; SEInfo.Wnd := 0; SEInfo.lpVerb := 'open'; SEInfo.lpFile := PChar('Explorer.exe') ; SEInfo.lpParameters := PChar(TempFile); SEInfo.lpDirectory := PChar(StartInString) ; SEInfo.nShow := SW_SHOWNORMAL; if ShellExecuteEx(@SEInfo) then begin GetExitCodeProcess(SEInfo.hProcess, ExitCode) ; ProcessID := GetProcessIDbyProcessHandle(SEInfo.hProcess); end; |
blue
中階會員 ![]() ![]() ![]() 發表:170 回覆:136 積分:81 註冊:2002-04-15 發送簡訊給我 |
暫時處理,仍不解
使用 FindExecutable先找出關聯程式的位置,但使用ShellExecuteEx仍會無法找出ProcessID,改用 JvCreateProcess 則可以找出ProcessID,但,Handle卻又=0,還是卡住了.... Ret := FindExecutable(PChar(TempFile), '', AssocPrg); sAssocPrg := AssocPrg; if Ret > 32 then begin JvCreateProcess1.CommandLine := sAssocPrg ' ' TempFile; end else begin JvCreateProcess1.CommandLine := 'Explorer.exe ' TempFile; end; with JvCreateProcess1 do begin case State of psReady: begin Run; end; psRunning, psWaiting: begin JvCreateProcess1.CloseApplication; end; end; end; ProgramWnd := FindMainWindow(JvCreateProcess1.ProcessInfo.dwProcessID); ProcessID := JvCreateProcess1.ProcessInfo.dwProcessID; ===================引 用 blue 文 章=================== Hi,各位先進大家好: 小弟遇到一個奇怪問題不知該如何解決, 小弟希望開啟使用者所選定的文件(可能是Word, Excel....不定) 使用 ShellExecuteEX啟動文件後希望取得該程式的ProcessID, 程式如后附, 但,問題來了,以下的程式所取的是這支程式的ProssID,不是關聯到文件的那個程式的ID, 若是將 Explorer.exe 改為Winword.exe(假設Tempfile是一個Word文件),則可以正常取得Winword的ProcessID, 謝謝! FillChar(SEInfo, SizeOf(SEInfo), 0) ; SEInfo.cbSize := SizeOf(TShellExecuteInfo); SEInfo.fMask := SEE_MASK_NOCLOSEPROCESS; SEInfo.Wnd := 0; SEInfo.lpVerb := 'open'; SEInfo.lpFile := PChar('Explorer.exe') ; SEInfo.lpParameters := PChar(TempFile); SEInfo.lpDirectory := PChar(StartInString) ; SEInfo.nShow := SW_SHOWNORMAL; if ShellExecuteEx(@SEInfo) then begin GetExitCodeProcess(SEInfo.hProcess, ExitCode) ; ProcessID := GetProcessIDbyProcessHandle(SEInfo.hProcess); end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |