Posts: 767
Threads: 262
Joined: Jul 2012
Is it possible to keep the cmd open after runconsole2 is executed.
Now it executes the .exe in the runconsole2 command and closes immediately after .exe is finished.
Or is there another way to do this?
The only way I know is to start cmd, wait for it's window to become visible and active, then use control+v or sendkeys.
But I was wondering if there is a more robust/effective way to do this?
I also looked in the "run" command (window options) but couldn't find it there.
Posts: 1,337
Threads: 61
Joined: Jul 2006
08-15-2018, 06:23 PM
(This post was last modified: 08-15-2018, 07:00 PM by Kevin.)
Posts: 12,089
Threads: 142
Joined: Dec 2002
08-15-2018, 08:45 PM
(This post was last modified: 08-15-2018, 09:07 PM by Gintaras.)
Use cmd command line, not paste/key.
Macro
Macro36
run "cmd.exe" "/K taskkill.exe /?"
Or create console exe from the macro:
Macro
Macro37
;/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
;/
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
Posts: 767
Threads: 262
Joined: Jul 2012
08-15-2018, 11:53 PM
(This post was last modified: 08-15-2018, 11:55 PM by r0n.)
Thank you both!!!