6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
8 * 2014 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #define NTOS_MODE_USER
28 #include <ndk/psfuncs.h>
30 void ProcessPage_OnEndProcess(void)
35 WCHAR strErrorText
[260];
37 dwProcessId
= GetSelectedProcessId();
42 hProcess
= OpenProcess(PROCESS_TERMINATE
| PROCESS_QUERY_INFORMATION
, FALSE
, dwProcessId
);
44 /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
45 if (hProcess
&& IsCriticalProcess(hProcess
))
47 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
48 LoadStringW(hInst
, IDS_MSG_CLOSESYSTEMPROCESS
, strErrorText
, 256);
49 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONWARNING
|MB_TOPMOST
);
50 CloseHandle(hProcess
);
54 /* if this is a standard process just ask for confirmation before doing it */
55 LoadStringW(hInst
, IDS_MSG_WARNINGTERMINATING
, strErrorText
, 256);
56 LoadStringW(hInst
, IDS_MSG_TASKMGRWARNING
, szTitle
, 256);
57 if (MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_YESNO
|MB_ICONWARNING
|MB_TOPMOST
) != IDYES
)
59 if (hProcess
) CloseHandle(hProcess
);
63 /* no such process or not enough privileges to open its token */
66 GetLastErrorText(strErrorText
, 260);
67 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
68 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONSTOP
|MB_TOPMOST
);
72 /* try to kill it, and notify the user if didn't work */
73 if (!TerminateProcess(hProcess
, 1))
75 GetLastErrorText(strErrorText
, 260);
76 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
77 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONSTOP
|MB_TOPMOST
);
80 CloseHandle(hProcess
);
83 BOOL
IsCriticalProcess(HANDLE hProcess
)
86 ULONG BreakOnTermination
;
88 /* return early if the process handle does not exist */
92 /* the important system processes that we don't want to let the user
93 kill come marked as critical, this simplifies the check greatly.
95 a critical process brings the system down when is terminated:
96 <http://www.geoffchappell.com/studies/windows/win32/ntdll/api/rtl/peb/setprocessiscritical.htm> */
98 status
= NtQueryInformationProcess(hProcess
,
99 ProcessBreakOnTermination
,
104 if (NT_SUCCESS(status
) && BreakOnTermination
)
110 void ProcessPage_OnEndProcessTree(void)
115 WCHAR strErrorText
[260];
117 dwProcessId
= GetSelectedProcessId();
119 if (dwProcessId
== 0)
122 hProcess
= OpenProcess(PROCESS_TERMINATE
| PROCESS_QUERY_INFORMATION
, FALSE
, dwProcessId
);
124 /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
125 if (hProcess
&& IsCriticalProcess(hProcess
))
127 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
128 LoadStringW(hInst
, IDS_MSG_CLOSESYSTEMPROCESS
, strErrorText
, 256);
129 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONWARNING
|MB_TOPMOST
);
130 CloseHandle(hProcess
);
134 LoadStringW(hInst
, IDS_MSG_WARNINGTERMINATING
, strErrorText
, 256);
135 LoadStringW(hInst
, IDS_MSG_TASKMGRWARNING
, szTitle
, 256);
136 if (MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_YESNO
|MB_ICONWARNING
) != IDYES
)
138 if (hProcess
) CloseHandle(hProcess
);
144 GetLastErrorText(strErrorText
, 260);
145 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
146 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONSTOP
);
150 if (!TerminateProcess(hProcess
, 0))
152 GetLastErrorText(strErrorText
, 260);
153 LoadStringW(hInst
, IDS_MSG_UNABLETERMINATEPRO
, szTitle
, 256);
154 MessageBoxW(hMainWnd
, strErrorText
, szTitle
, MB_OK
|MB_ICONSTOP
);
157 CloseHandle(hProcess
);