Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keep cmd window open?
#3
Use cmd command line, not paste/key.
Macro Macro36
Code:
Copy      Help
run "cmd.exe" "/K taskkill.exe /?"

Or create console exe from the macro:
Macro Macro37
Code:
Copy      Help
;/exe
CreateProcessSimple "taskkill.exe /?" 1
ExeConsoleWrite "[]Press any key to exit..."
getch

;BEGIN PROJECT
;main_function  Macro37
;exe_file  $my qm$\Macro37.exe
;icon  <default>
;manifest  $qm$\default.exe.manifest
;flags  70
;END PROJECT


Function CreateProcessSimple
Code:
Copy      Help
;/
function# $cl [flags] ;;flags: 1 wait until exits, 2 return handle, 4 inherit uiAccess

;Calls CreateProcess.
;By default returns pid. If flag 2 - handle. If flag 1 - 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
int R ok
if flags&4
,__Handle hToken
,OpenProcessToken(GetCurrentProcess() TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_ASSIGN_PRIMARY &hToken)
,ok=CreateProcessAsUserW(hToken 0 @cl 0 0 0 0 0 0 &si &pi)
else
,ok=CreateProcessW(0 @cl 0 0 0 0 0 0 &si &pi)
if(!ok) end _s.dllerror
CloseHandle pi.hThread
R=pi.dwProcessId

if flags&1
,opt waitmsg -1
,wait 0 H pi.hProcess
,GetExitCodeProcess pi.hProcess &R

if(flags&2) R=pi.hProcess; else CloseHandle pi.hProcess

ret R


Messages In This Thread
Keep cmd window open? - by r0n - 08-15-2018, 04:27 AM
RE: Keep cmd window open? - by Kevin - 08-15-2018, 06:23 PM
RE: Keep cmd window open? - by Gintaras - 08-15-2018, 08:45 PM
RE: Keep cmd window open? - by r0n - 08-15-2018, 11:53 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)