What's new

Win32: CreateProcess and process termination

Cyberman

Moderator
Moderator
I believe I'm missing something here, I am using
Code:
            CreateProcess
                (
                NULL,//"cmd.exe",        // include module name
                cmd_line.c_str(),    // use generated command line
                NULL,                // Process handle not inherited
                NULL,                // Thread handle not inherited
                FALSE,            // handle inheritance is false
                CREATE_NEW_PROCESS_GROUP,
                    // make a process group for CTRL BREAK To terminate it
                NULL,                // use parent environment
                NULL,                // use parent starting directory
                &start_information,
                &com_process[index]
                )
This works and requires a control break to close the window however

When I use this to terminate the process
Code:
            if(!GenerateConsoleCtrlEvent
                    (
                    CTRL_BREAK_EVENT,
                    //com_process[index].hProcess
                    com_process[index].dwProcessId
                    )
                )
The process ID returned by CreateProcess appears to be invalid (that's what windows complains at least). Thoughts as to WHY they are invalid?
I have th current manually send CTRL break to them (currently there are 6 tolerable but I prefer not to sift through processes and CTRL-BREAK in there window personally).

I attempted originally to use TerminateProcess but that appears to have other issues (first you have to do all sorts of security twiddling) this seemed the better route.

Side note What is it with MS and NON STANDARD interfaces? There is no SIGINT support yet it exists in there API information and yet they don't actually support it. I suppose it's because of the redefinition of CTRL ALT DEL (yet another genius idea).

Anyhow :D

Cyb
 

smcd

Active member
Do you ZeroMem (a macro, basically memset...) the structs before giving them to CreateProcess? Also, some of them have a size/length parameter that need set too (sizeof)
 
OP
Cyberman

Cyberman

Moderator
Moderator
Yes I clear the structures (
Code:
memset(start_information, 0, sizeof(start_information));
start_information.cb = sizeof(start_information);
memset(com_process[index], 0, sizeof(com_process[index]));
I've successfully used CreateProcess before this one just puzzles me why I can't kill them. In fact I am using it in a newer project however I simply idle the program until the called program finishes, not exactly the same type of thing. It's a bit annoying to say the least.

Cyb
 

smcd

Active member
I've had a similar issue in the past but I cannot remember what it was. Ended up being something trivial that wasn't being done correctly. Will dig through some code an see if I can find it
 
OP
Cyberman

Cyberman

Moderator
Moderator
Obviously not 'high priority' at the moment for me. LOL.

It works the user just has to nuke windows afterward. Funny thing is if they don't it doesn't open NEW processes it uses the old ones without causing a single glitch. Then again they operate independently of the calling program, I suspect that it just replaces the original processes with new ones and the old ones automatically nuke themselves. Oh well.

Cyb
 

Top