I have a problem spawning processes from a windows service. The problem is not actually starting the process, but showing the console of the process. I can understand that the windows services do not have consoles and do not take any user input and therefore the spawned processes which inherit their console attributes would do the same.
However, I am spawning a separate process using DETACH_PROCESS flag in the CreateProcess function and even if I am calling AllocConsole right at the start of the child process, nothing shows on the screen (I am calling a console-mode application).
Below is the function I am using for starting a certain process:
int PRAPI ExecuteProgram2(const char *program, const char **args, BOOL wait_for_finish)
char **ptr = (char **)args;
memset(buf, 0, 2048);
while (ptr && *ptr)
sprintf(tmp," %s", *ptr);
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
//start log console window
CREATE_DEFAULT_ERROR_MODE | DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP ,
err = GetLastError();
Please don't mind any buffer overflows or any other bugs, this is a test function.
The program starts but it wont show any console.
Any advice is greatly appreciated.