Inno Setup Exec() function Wait for a limited time -
in inno setup script executing 3rd party executable. using exec() function below:
exec(expandconstant('{app}\someexe.exe'), '', '', sw_hide, ewwaituntilterminated, errorcode); by mentioning ewwaituntilterminated waits until someexe.exe doesn't quit. want wait 10 secs.
is there solution that?
assuming want execute external application, waiting termination specified time , if it's not terminated killing setup try following code. magical constants used here, 3000 used parameter in waitforsingleobject function time in milliseconds how long setup wait process terminate. if doesn't terminate in time itself, killed terminateprocess function, 666 value process exit code (quite evil in case :-)
[code] #ifdef unicode #define aw "w" #else #define aw "a" #endif const wait_timeout = $00000102; see_mask_nocloseprocess = $00000040; type tshellexecuteinfo = record cbsize: dword; fmask: cardinal; wnd: hwnd; lpverb: string; lpfile: string; lpparameters: string; lpdirectory: string; nshow: integer; hinstapp: thandle; lpidlist: dword; lpclass: string; hkeyclass: thandle; dwhotkey: dword; hmonitor: thandle; hprocess: thandle; end; function shellexecuteex(var lpexecinfo: tshellexecuteinfo): bool; external 'shellexecuteex{#aw}@shell32.dll stdcall'; function waitforsingleobject(hhandle: thandle; dwmilliseconds: dword): dword; external 'waitforsingleobject@kernel32.dll stdcall'; function terminateprocess(hprocess: thandle; uexitcode: uint): bool; external 'terminateprocess@kernel32.dll stdcall'; function nextbuttonclick(curpageid: integer): boolean; var execinfo: tshellexecuteinfo; begin result := true; if curpageid = wpwelcome begin execinfo.cbsize := sizeof(execinfo); execinfo.fmask := see_mask_nocloseprocess; execinfo.wnd := 0; execinfo.lpfile := 'calc.exe'; execinfo.nshow := sw_hide; if shellexecuteex(execinfo) begin if waitforsingleobject(execinfo.hprocess, 3000) = wait_timeout begin terminateprocess(execinfo.hprocess, 666); msgbox('you killed little kitty!', mberror, mb_ok); end else msgbox('the process terminated in time!', mbinformation, mb_ok); end; end; end; the code i've tested inno setup 5.4.3 unicode , ansi version on windows 7 (thanks kobik idea use conditional defines windows api function declarations this post)
Comments
Post a Comment