You can write your own ShellExecute with
CreateProcess and synchronize the call with
WaitForSingleObjectEx on the process handle. The attached sample procedure uses this technique:
[tt]
BOOL SpawnProc(int CreationFlags, BOOL Sync, int argc, char *argv[])
{
// va_list argptr;
// char *parm = Param, CmdLine[256];
char CmdLine[256];
int i = 0;
PROCESS_INFORMATION ProcessInformation;
// LPSECURITY_ATTRIBUTES lpProcessAttributes, lpThreadAttributes;
STARTUPINFO si;
ZeroMemory (&si, sizeof(STARTUPINFO));
si.cb = sizeof(si);
si.wShowWindow = SW_MINIMIZE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
CmdLine[0] = '\0';
// va_start( argptr, Param ); /* Initialize variable arguments. */
for (i = 1; argv
!= NULL && i < 256; i++) {
strcat (CmdLine, "\""
;
strcat (CmdLine, argv);
strcat (CmdLine, "\" "
;
// parm = va_arg( argptr, char *);
}
CmdLine = '\0';
printf ("Exe: %s - CmdLine: %s\n", argv[0], CmdLine);
// va_end( argptr ); /* Reset variable arguments. */
// LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_STARTING_SERVICE, "CreateProcess ", CmdLine);
if (CreateProcess(
argv[0], // pointer to name of executable module
CmdLine, // pointer to command line string
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
FALSE, // handle inheritance flag
CreationFlags, // creation flags
NULL, // pointer to new environment block
NULL, // pointer to current directory name
&si, // pointer to STARTUPINFO
&ProcessInformation // pointer to PROCESS_INFORMATION
))
{
if (Sync) {
::WaitForSingleObjectEx(
ProcessInformation.hProcess, // handle of object to wait for
INFINITE, // time-out interval in milliseconds
FALSE // return to execute I/O completion routine if TRUE
);
}
return TRUE;
} else {
// LogEvent(EVENTLOG_ERROR_TYPE, EVMSG_PROC_START_FAIL, CmdLine);
return FALSE;
};
}
[/tt]