Hello,
I have a small win32 program which starts
and stops apache (win) as a program (not service)
in a hidden console.
---snip---
/* global vars */
STARTUPINFO g_sia;
PROCESS_INFORMATION g_pia;
[...]
void StartApache()
{
g_sia.dwFlags = STARTF_USESHOWWINDOW;
g_sia.wShowWindow = SW_HIDE;
CreateProcess(NULL, "apache.exe...", NULL, NULL, FALSE,
CREATE_NEW_PROCESS_GROUP, NULL, NULL, &g_sia, &g_pia);
}
---snap---
using "CREATE_NEW_PROCESS_GROUP" described at:
http://msdn.microsoft.com/en-us/library/ms684863(VS.85).aspx
At the end I would like to shutdown apache in an "usual"
way and sending an CTRL+C to the console. Using
GenerateConsoleCtrlEvent(). See:
http://msdn.microsoft.com/en-us/library/ms683155(VS.85).aspx
btw: actually I terminate apache, using
CreateToolhelp32Snapshot() and iterate all child processes
and using TerminateProcess().
but I would prefer to generate an CTRL+C Signal
---snip---
void StopApache()
{
GenerateConsoleCtrlEvent(CTRL_C_EVENT, g_pia.dwProcessId);
}
---snap---
but got an Error #6 = "The handle is invalid" with GetLastError()
and nothing happens and apache is still runing.
Why? And how can I shutdown apache in this way
using the signal Ctrl+C Signal in Windows? The pid is a
global var and contains the pid of the parent process.
Should be valid - shouldn't it?
Thomas