Hi,
thanks for the info.
CreateProcess
+
GetExitCodeProcess
works.
The following sample code looks give what expected.
The problem is only that I have not found a way to tell
CreateProcess
the flag
PROCESS_QUERY_INFORMATION
.
For some reason that flag was not necessary ...mmmm ... anyone knows the right way to set it?
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, PROCESS_QUERY_INFORMATION);
SetSecurityDescriptorDacl(&sd,TRUE,(PACL) NULL,FALSE);
SECURITY_ATTRIBUTES sa;
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
if(! CreateProcess(
NULL,
Msg_Exe,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
)){
int breakpoint;
breakpoint=0;
}
do{
DWORD exitCode;
if(! GetExitCodeProcess(pi.hProcess, &exitCode)){
int breakpoint;
breakpoint=0;
}else{
if(exitCode!=STILL_ACTIVE)
break;
printf("Program is running\r\n");
}
}while(1);
printf("Program is stop\r\n");