Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done Run a Windows program from another process

Aug
2,320
111
Add a new option to START that will run a windows program from another process.

For the last while, I have been using the RunFromProcess.exe utility to accomplish this.

Joe
 
I have this in my 4UTILS plugin. I'll help if I can.

Code:
v:\> spoofppid /?
Syntax: SPOOFPID [/P ProcessId] "command_line" [startup_directory]

    /P - use the specified ProcessId as parent; default: Explorer's ProcessId
    command_line and/or startup_directory containing spaces must be "quoted"
    escape internal quotes as \"
    TCC's environment is not inherited
    If <ProcessId> is unelevated, so will be the new process
 
I've using Version: 2019.527 Build 215026 of your 4Utils plugin,
but it does not have that command.

I have downloaded it from ftp://vefatica.net\4plugins\x64\4utils64.zip

Joe
 
I don't know where those version and build numbers are coming from, probably antiquity. They are 2019, 05/27 21:50:26. They're from an old file and I don't even remember how I got them into the file or from the file to the binary. I'll work on enhancing the version info. :-)

If you have Dev Studio and especially DUMPBIN.EXE you can see the compiler's time stamp. For example,

Code:
d:\data\tccplugins> dumpbin /headers 4utils64.dll | grep stamp
        67C26013 time date stamp Fri Feb 28 20:17:07 2025

For now I've put a new one in place (same place). Save your old one just in case.

SPOOFPPID is in there.

Two other things I worked on today: when the prompt is shown, it sets the internal variable _LASTPROMPT to hh:mm:ss.ttt and it sets the envoronment variable PROMPT_SHOWN to Yes. When a command is being executed, it leaves _LASTPROMPT alone and sets PROMPT_SHOWN to No. Both of those are experimental; they exist so a BTM run by thread THREAD command can tell if TCC's main thread has returned to the prompt. You can ignore them. There might be other new stuff in there.
 
SPOOFPPID does the same thing as RunFromProcess.exe

Well, that and a bit more. Spoofing the parent PID has nothing to do with the environment the new process gets; By default it inherits the environment of its REAL parent. If you're using RunFromProcess.exe, the newly-created process inherits the environment of RunFromProcess.exe (which , in turn, is inherited from whoever started it). In SPOOFPPID, the new process gets a "fresh" environment created using a user token HANDLE obtained from the spoofed process. Is that significant to you?

In regards to _LASTPROMPT and PROMPT_SHOWN,
is this related to Can PRE_EXEC refer to the about_to_be_executed command line? from back in April of 2023?

No, it's not. I wanted to use THREAD to run a BTM to monitor the output in TCC's main thread. The BTM can use one of those variables to tell when the main thread has returned to the prompt (so the BTM can quit and its thread can terminate).
 
Hey @vefatica;

Doing some simple testing...

PID 10804 tcc.exe
PID 12628 tcc.exe
PID 10112 cmd.exe


Tests launched from PID 10804.

This works;
Code:
runfromprocess-x64 12628 "e:\hb34\bin\hbmk2.exe" "u:\june17.prg"

This does not work;
Code:
spoofppid /p 12628 "e:\hb34\bin\hbmk2.exe" "u:\june17.prg"
TCC: (Sys) The directory name is invalid.
 "CreateProcessW"

This works;
Code:
R:\>runfromprocess-x64 10112 "e:\hb34\bin\hbmk2.exe" "u:\june17.prg

This does not work;
Code:
R:\>spoofppid /p 10112 "e:\hb34\bin\hbmk2.exe" "u:\june17.prg"
TCC: (Sys) The directory name is invalid.
 "CreateProcessW"

Just using the Harbour compiler to compile a simple program in another process as a test.

Looking forward to V35 (Thanks @rconn )

Joe
 
OK here. Are those really directory names? And, if a directory name ends with a '\', get rid of it or double it.
 
AFAICT, after the process to spoof, runfromprocess takes a program name and then arguments to that program. With SPOOFPPID, the arguments are in the command.

Code:
SPOOFPPID /p PID "program arg1 arg2" "startup directory"
 
Back
Top