07-23-2014, 06:00 AM
If need just to return a single integer:
Function this_is_my_exe
Macro Macro2473
Function CreateProcessSimple
Function this_is_my_exe
;...
ret 5 ;;return an integer
;BEGIN PROJECT
;main_function this_is_my_exe
;exe_file $my qm$\this_is_my_exe.exe
;icon <default>
;manifest $qm$\default.exe.manifest
;flags 6
;guid {D3960F15-7393-4411-8A6A-0731CBBF8E01}
;END PROJECT
Function CreateProcessSimple
;/
function# $cl [flags] ;;flags: 1 wait until exits
;Calls CreateProcess.
;Returns 0. If flag 1, returns the exit code.
;Error if fails.
;cl - program path, optionally followed by command line arguments.
;;;Program path can be enclosed in quotes. Should be enclosed if contains spaces.
;flags:
;;;1 - wait until exits and return the exit code.
;NOTES
;CreateProcess fails if would show UAC consent. Use run() instead.
;EXAMPLE
;int ec=CreateProcessSimple("''$my qm$\this_is_my_exe.exe'' /a ''b''" 1)
;out ec
opt noerrorshere 1
sel cl 2
,case ["$*","%*"] cl=_s.expandpath(cl)
,case ["''$*","''%*"] _s.expandpath(cl+1); _s-"''"; cl=_s
STARTUPINFOW si.cb=sizeof(si)
PROCESS_INFORMATION pi
if(!CreateProcessW(0 @cl 0 0 0 0 0 0 &si &pi)) end _s.dllerror
CloseHandle pi.hThread
if flags&1
,opt waitmsg -1
,wait 0 H pi.hProcess
,int R
,GetExitCodeProcess pi.hProcess &R
CloseHandle pi.hProcess
ret R