Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command Line Parameters on an EXE
#17
If need just to return a single integer:

Function this_is_my_exe
Code:
Copy      Help
;...
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
Macro Macro2473
Code:
Copy      Help
int ec=CreateProcessSimple("''$my qm$\this_is_my_exe.exe'' /a ''b''" 1)
out ec
Function CreateProcessSimple
Code:
Copy      Help
;/
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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)