mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[TASKMGR] Implement proper process tree ending
* Implement ShutdownProcessTree in endproc.c which recursively kills process trees * Include tlhelp32.h in precomp.h * Check if the child process can be shut down
This commit is contained in:
parent
66bf74d228
commit
3276824586
2 changed files with 53 additions and 1 deletions
|
@ -107,6 +107,57 @@ BOOL IsCriticalProcess(HANDLE hProcess)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL ShutdownProcessTreeHelper(HANDLE hSnapshot, HANDLE hParentProcess, DWORD dwParentPID)
|
||||||
|
{
|
||||||
|
HANDLE hChildHandle;
|
||||||
|
PROCESSENTRY32W ProcessEntry = {0};
|
||||||
|
ProcessEntry.dwSize = sizeof(ProcessEntry);
|
||||||
|
|
||||||
|
if (Process32FirstW(hSnapshot, &ProcessEntry))
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (ProcessEntry.th32ParentProcessID == dwParentPID)
|
||||||
|
{
|
||||||
|
hChildHandle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
|
||||||
|
FALSE,
|
||||||
|
ProcessEntry.th32ProcessID);
|
||||||
|
if (!hChildHandle || IsCriticalProcess(hChildHandle))
|
||||||
|
{
|
||||||
|
if (hChildHandle)
|
||||||
|
{
|
||||||
|
CloseHandle(hChildHandle);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!ShutdownProcessTreeHelper(hSnapshot, hChildHandle, ProcessEntry.th32ProcessID))
|
||||||
|
{
|
||||||
|
CloseHandle(hChildHandle);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
CloseHandle(hChildHandle);
|
||||||
|
}
|
||||||
|
} while (Process32NextW(hSnapshot, &ProcessEntry));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TerminateProcess(hParentProcess, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ShutdownProcessTree(HANDLE hParentProcess, DWORD dwParentPID)
|
||||||
|
{
|
||||||
|
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
BOOL bResult;
|
||||||
|
|
||||||
|
if (!hSnapshot)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bResult = ShutdownProcessTreeHelper(hSnapshot, hParentProcess, dwParentPID);
|
||||||
|
CloseHandle(hSnapshot);
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessPage_OnEndProcessTree(void)
|
void ProcessPage_OnEndProcessTree(void)
|
||||||
{
|
{
|
||||||
DWORD dwProcessId;
|
DWORD dwProcessId;
|
||||||
|
@ -147,7 +198,7 @@ void ProcessPage_OnEndProcessTree(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TerminateProcess(hProcess, 0))
|
if (!ShutdownProcessTree(hProcess, dwProcessId))
|
||||||
{
|
{
|
||||||
GetLastErrorText(strErrorText, 260);
|
GetLastErrorText(strErrorText, 260);
|
||||||
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <winreg.h>
|
#include <winreg.h>
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
|
|
||||||
#include "column.h"
|
#include "column.h"
|
||||||
#include "taskmgr.h"
|
#include "taskmgr.h"
|
||||||
|
|
Loading…
Reference in a new issue