I'm trying to check if the process, started from the service, is running.
The problem is, that we migrate our app from Windows XP to Windows 7. One part of this app is the service, which starts some processes. Another part is a dialog app. This dialog app try to recognize if the processes from service are running.
The pids of processes are stored in shared memory, so I can get the handle to process using OpenProcess()
from WinApi, and that works on the Windows XP. If I try to do it on Windows 7, the function give me error - access denied.
I think, that I know, why is so (new 0 level isolation in Windows7), but I need to find some workaround.
My question is if there is possible to set access permissions on created process and how (please give me some example with explanation)?
I found, that there is a parameter in CreateProcess()
and there is a function SetSecurityInfo()
, but I use this functions probably in bad way, because does not work.
To check, if the process is running I used
running = (WaitForSingleObject( handle, 0 ) == WAIT_TIMEOUT);
or
BOOL result = GetExitCodeProcess(handle, (LPDWORD) &code);
if(result) {
if(code == STILL_ACTIVE) {
running = true;
}
}
where handle
is taken from the OpenProcess()
function - OpenProcess( PROCESS_ALL_ACCESS , FALSE, pid );
I've also tried with SYNCHRONIZE
, PROCESS_QUERY_INFORMATION
and PROCESS_QUERY_LIMITED_INFORMATION
. But always access denied..
Every idea will be useful.