mirror of
https://github.com/reactos/reactos.git
synced 2024-09-30 14:37:45 +00:00
553b905ab4
Some commits I do port back all the way down till releases/0.4.7: partially 0.4.15-dev-6768-g63eaf2bd52
[TASKMGR] *.rc Deduplicate dynamic menu strings (#5772) (I left out the FIXME-comments) 0.4.15-dev-6712-g46b4b5581d
[TASKMGR] Favor _countof(), no functional change intended (#5757) 0.4.15-dev-6703-g6528ab8fcb
[TASKMGR] de-DE.rc Update part 3 0.4.15-dev-6702-g65ce20896a
[TASKMGR] *.rc Strip unused IDD_DEBUG_CHANNELS_DIALOG 0.4.15-dev-6700-ge15d68ba5d
[TASKMGR] de-DE German Update & bug-fixes partially 0.4.15-dev-6447-g016acd170d
[TASKMGR] Do not free shared icon for ShellAbout() calls (I picked just the taskmgr part) (was part of larger PR5519) 0.4.15-dev-6297-g831288fe69
[TASKMGR] Fix text truncation for fr-FR.rc (#5380) CORE-18523 0.4.15-dev-6127-gc706222f3f
[TASKMGR] Fix the license. Turns out it's LGPL-2.1-or-later from the texts. 0.4.15-dev-6124-g9927163455
[TASKMGR] Reorder page controls to have natural TAB-ordering. 0.4.15-dev-6122-gd5707eefe2
[TASKMGR] High speed update is twice per second, and not every second. 0.4.15-dev-6121-g2da0506f2a
[TASKMGR] Remove more dead code. partially 0.4.15-dev-6120-g6e77747b30
[TASKMGR] Simplify tray icon code. (I left out using the strsafe.h-dependent stuff, as this is safe also in old-style) 0.4.15-dev-6119-g0b4c8bdd1c
[TASKMGR] Clamp the values returned from PerfDataGetProcessorUsage() and PerfDataGetProcessorSystemUsage() inside these functions. 0.4.15-dev-6118-g7b53126375
[TASKMGR] Completely reformat perfpage.c, perfpage.h, procpage.h and trayicon.c partially 0.4.15-dev-6117-gda7dcec6a0
[TASKMGR] Reformat the files' headers 0.4.15-dev-6115-g36aea8e56e
[TASKMGR] affinity.c: Use _countof instead of sizeof/sizeof (was part of the larger CORE18991) partially 0.4.15-dev-6109-g99fb812be4
[TASKMGR] Refactor trayicon.c 0.4.15-dev-5404-gc093d4f803
[TASKMGR] Prevent context menu on idle process (#4889) CORE-18640 0.4.15-dev-5031-g46ea5171bd
[TASKMGR] Pixel-perfection for left border (#4680) CORE-18061 0.4.15-dev-4988-gde5af76811
[TASKMGR] Fix overlapping controls (French only) (#4658) 0.4.15-dev-4987-gf8c28b9773
[TASKMGR] Fix UI on SwitchTo for multiple application (#4652) 0.4.15-dev-3497-ge8a7e0da2b
[TASKMGR] Make 'Hide When Minimized' non-default (#4169) 0.4.15-dev-3085-g515e0cf38f
[TASKMGR] Handles: Get number only, skip data (#3910) and a few *.rc improvements that are not explicitly mentioned here, especially I stripped the menuLoop-statusbar-help-texts within the older branches. I also port back the following feature into all releases down to releases/0.4.8, but I left out releases/0.4.7 for now: 0.4.13-dev-875-g3276824586
[TASKMGR] Implement proper process tree ending (#1738) A few improvements are still left to be done in a future commit (mostly around the plotgraphs and the trayicon-handling), but I need to have a closer look at them and their impact on binary size, so I do not want to squash them into this bigger backport, where I concentrated on the safe/obvious and easy things. Binary size decreases for all branches: master taskmgr.exe RosBEWin2.2.2 GCC8.4.0dbg 708.608 -> 696.832 (0.4.15-dev-6768-g63eaf2b) 0.4.14 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 660.992 -> 549.888 0.4.13 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 659.968 -> 542.720 0.4.12 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 662.016 -> 545.792 0.4.11 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 662.016 -> 545.792 0.4.10 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 645.120 -> 532.480 0.4. 9 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 645.120 -> 532.480 0.4. 8 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 645.120 -> 532.480 0.4. 7 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 645.120 -> 531.456 taskmgr.exe MS XPSP3 german 140.800 Bytes 0.4.14 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=de-DE -> 110.080 Bytes (my current taskmgr of choice) 0.4. 8 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=en-US -> 108.032 Bytes 0.4. 7 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=en-US -> 107.520 Bytes
190 lines
6 KiB
C
190 lines
6 KiB
C
/*
|
|
* PROJECT: ReactOS Task Manager
|
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
* COPYRIGHT: 1999-2001 Brian Palmer <brianp@reactos.org>
|
|
* 2005 Klemens Friedl <frik85@reactos.at>
|
|
* 2014 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
|
|
*/
|
|
|
|
#include "precomp.h"
|
|
|
|
#define NTOS_MODE_USER
|
|
#include <ndk/psfuncs.h>
|
|
|
|
void ProcessPage_OnEndProcess(void)
|
|
{
|
|
DWORD dwProcessId;
|
|
HANDLE hProcess;
|
|
WCHAR szTitle[256];
|
|
WCHAR strErrorText[260];
|
|
|
|
dwProcessId = GetSelectedProcessId();
|
|
|
|
if (dwProcessId == 0)
|
|
return;
|
|
|
|
hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
|
|
|
|
/* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
|
|
if (hProcess && IsCriticalProcess(hProcess))
|
|
{
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONWARNING|MB_TOPMOST);
|
|
CloseHandle(hProcess);
|
|
return;
|
|
}
|
|
|
|
/* if this is a standard process just ask for confirmation before doing it */
|
|
LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
|
|
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
|
|
if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING|MB_TOPMOST) != IDYES)
|
|
{
|
|
if (hProcess) CloseHandle(hProcess);
|
|
return;
|
|
}
|
|
|
|
/* no such process or not enough privileges to open its token */
|
|
if (!hProcess)
|
|
{
|
|
GetLastErrorText(strErrorText, 260);
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP|MB_TOPMOST);
|
|
return;
|
|
}
|
|
|
|
/* try to kill it, and notify the user if didn't work */
|
|
if (!TerminateProcess(hProcess, 1))
|
|
{
|
|
GetLastErrorText(strErrorText, 260);
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP|MB_TOPMOST);
|
|
}
|
|
|
|
CloseHandle(hProcess);
|
|
}
|
|
|
|
BOOL IsCriticalProcess(HANDLE hProcess)
|
|
{
|
|
NTSTATUS status;
|
|
ULONG BreakOnTermination;
|
|
|
|
/* return early if the process handle does not exist */
|
|
if (!hProcess)
|
|
return FALSE;
|
|
|
|
/* the important system processes that we don't want to let the user
|
|
kill come marked as critical, this simplifies the check greatly.
|
|
|
|
a critical process brings the system down when is terminated:
|
|
<http://www.geoffchappell.com/studies/windows/win32/ntdll/api/rtl/peb/setprocessiscritical.htm> */
|
|
|
|
status = NtQueryInformationProcess(hProcess,
|
|
ProcessBreakOnTermination,
|
|
&BreakOnTermination,
|
|
sizeof(ULONG),
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(status) && BreakOnTermination)
|
|
return TRUE;
|
|
|
|
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)
|
|
{
|
|
DWORD dwProcessId;
|
|
HANDLE hProcess;
|
|
WCHAR szTitle[256];
|
|
WCHAR strErrorText[260];
|
|
|
|
dwProcessId = GetSelectedProcessId();
|
|
|
|
if (dwProcessId == 0)
|
|
return;
|
|
|
|
hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
|
|
|
|
/* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
|
|
if (hProcess && IsCriticalProcess(hProcess))
|
|
{
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONWARNING|MB_TOPMOST);
|
|
CloseHandle(hProcess);
|
|
return;
|
|
}
|
|
|
|
LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
|
|
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
|
|
if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
|
|
{
|
|
if (hProcess) CloseHandle(hProcess);
|
|
return;
|
|
}
|
|
|
|
if (!hProcess)
|
|
{
|
|
GetLastErrorText(strErrorText, 260);
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
|
return;
|
|
}
|
|
|
|
if (!ShutdownProcessTree(hProcess, dwProcessId))
|
|
{
|
|
GetLastErrorText(strErrorText, 260);
|
|
LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
|
|
MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
|
|
}
|
|
|
|
CloseHandle(hProcess);
|
|
}
|