My code first calls TerminateProcess() using the process handle
returned in the PROCESS_INFORMATION structure during CreateProcess(),
and if that fails I then call OpenProcess(PROCESS_TERMINATE, ...) to
make sure I have terminate rights, and then call TerminateProcess()
using that handle, and it still fails with ERROR_ACCESS_DENIED.
So what could be preventing TerminateProcess() from doing its dirty
work? Is it because the second process has a COM object still active
(it's probably the COM object that's causing the process to hang)?
What can I do, to make sure that I can terminate this second process?
Thanks,
Chris
Make sure to check return value from CreateProcess for zero, before calling
GetLastError().
"Chris Shearer Cooper" <chris.shea...@gmail.com> wrote in message
news:a3183305-0a61-403e...@f36g2000hsa.googlegroups.com...
I am checking all functions, including CreateProcess(), for failure.
They are all fine, except for TerminateProcess().
Chris
On Aug 7, 8:24 am, "Alexander Grigoriev" <al...@earthlink.net> wrote:
> Make sure you don't habitually close the process handle immediately after
> CreateProcess call. This handle has full rights to the process.
>
> Make sure to check return value from CreateProcess for zero, before calling
> GetLastError().
>
> "Chris Shearer Cooper" <chris.shearer.coo...@gmail.com> wrote in messagenews:a3183305-0a61-403e...@f36g2000hsa.googlegroups.com...
"Chris Shearer Cooper" <chris.shea...@gmail.com> wrote in message
news:37c27195-35db-478b...@2g2000hsn.googlegroups.com...
m_hProcess = process.hProcess;
m_lProcessId = process.dwProcessId;
CloseHandle(process.hThread); // We don't keep the thread handle
// and then much later ...
BOOL bTerminate = ::TerminateProcess(m_hProcess, 12);
if (bTerminate)
return;
DWORD lError = GetLastError();
if (lError != ERROR_ACCESS_DENIED)
{
TRACE("Error %d terminating (process %d)\n", lError,
m_lProcessId);
return;
}
// Access is denied.
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE,
m_lProcessId);
if (hProcess == NULL)
{
DWORD lError = GetLastError();
TRACE("OpenProcess(%d) failed with error %d\n", m_lProcessId,
lError);
return;
}
bTerminate = ::TerminateProcess(hProcess, 12);
if (bTerminate)
{
DWORD lError = GetLastError();
TRACE("Only able to terminate after OpenProcess(PROCESS_TERMINATE)
\n");
}
else
{
DWORD lError = GetLastError();
TRACE("Error %d terminating (process %d)\n", lError,
m_lProcessId);
}
CloseHandle(hProcess);
On Aug 7, 8:41 pm, "Alexander Grigoriev" <al...@earthlink.net> wrote:
> Show your TerminateProcess call and how you check its success.
>
> "Chris Shearer Cooper" <chris.shearer.coo...@gmail.com> wrote in messagenews:37c27195-35db-478b...@2g2000hsn.googlegroups.com...
"Chris Shearer Cooper" <chris.shea...@gmail.com> wrote in message
news:e182d577-5d52-4a8d...@x35g2000hsb.googlegroups.com...
Regards,
Roger.
Thanks,
Chris