ReactOS 0.4.15-dev-7918-g2a2556c
endproc.c File Reference
#include "precomp.h"
#include <ndk/psfuncs.h>
Include dependency graph for endproc.c:

Go to the source code of this file.

Macros

#define NTOS_MODE_USER
 

Functions

void ProcessPage_OnEndProcess (void)
 
BOOL IsCriticalProcess (HANDLE hProcess)
 
BOOL ShutdownProcessTreeHelper (HANDLE hSnapshot, HANDLE hParentProcess, DWORD dwParentPID)
 
BOOL ShutdownProcessTree (HANDLE hParentProcess, DWORD dwParentPID)
 
void ProcessPage_OnEndProcessTree (void)
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 12 of file endproc.c.

Function Documentation

◆ IsCriticalProcess()

BOOL IsCriticalProcess ( HANDLE  hProcess)

Definition at line 68 of file endproc.c.

69{
71 ULONG BreakOnTermination;
72
73 /* return early if the process handle does not exist */
74 if (!hProcess)
75 return FALSE;
76
77 /* the important system processes that we don't want to let the user
78 kill come marked as critical, this simplifies the check greatly.
79
80 a critical process brings the system down when is terminated:
81 <http://www.geoffchappell.com/studies/windows/win32/ntdll/api/rtl/peb/setprocessiscritical.htm> */
82
85 &BreakOnTermination,
86 sizeof(ULONG),
87 NULL);
88
89 if (NT_SUCCESS(status) && BreakOnTermination)
90 return TRUE;
91
92 return FALSE;
93}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
@ ProcessBreakOnTermination
Definition: winternl.h:398
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ProcessPage_OnEndProcess(), ProcessPage_OnEndProcessTree(), and ShutdownProcessTreeHelper().

◆ ProcessPage_OnEndProcess()

void ProcessPage_OnEndProcess ( void  )

Definition at line 15 of file endproc.c.

16{
17 DWORD dwProcessId;
19 WCHAR szTitle[256];
20 WCHAR strErrorText[260];
21
22 dwProcessId = GetSelectedProcessId();
23
24 if (dwProcessId == 0)
25 return;
26
28
29 /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
31 {
33 LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
36 return;
37 }
38
39 /* if this is a standard process just ask for confirmation before doing it */
40 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
43 {
45 return;
46 }
47
48 /* no such process or not enough privileges to open its token */
49 if (!hProcess)
50 {
51 GetLastErrorText(strErrorText, 260);
54 return;
55 }
56
57 /* try to kill it, and notify the user if didn't work */
59 {
60 GetLastErrorText(strErrorText, 260);
63 }
64
66}
#define IDS_MSG_CLOSESYSTEMPROCESS
Definition: resource.h:258
#define IDS_MSG_WARNINGTERMINATING
Definition: resource.h:253
#define IDS_MSG_TASKMGRWARNING
Definition: resource.h:252
#define IDS_MSG_UNABLETERMINATEPRO
Definition: resource.h:254
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
HINSTANCE hInst
Definition: dxdiag.c:13
BOOL IsCriticalProcess(HANDLE hProcess)
Definition: endproc.c:68
unsigned long DWORD
Definition: ntddk_ex.h:95
#define PROCESS_TERMINATE
Definition: pstypes.h:157
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:166
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
HWND hMainWnd
Definition: magnifier.c:32
DWORD GetSelectedProcessId(void)
Definition: procpage.c:88
BOOL ConfirmMessageBox(HWND hWnd, LPCWSTR Text, LPCWSTR Title, UINT Type)
Definition: taskmgr.c:1059
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1083
#define MB_TOPMOST
Definition: winuser.h:825
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MB_YESNO
Definition: winuser.h:817
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_OK
Definition: winuser.h:790
#define MB_ICONWARNING
Definition: winuser.h:786
#define MB_ICONSTOP
Definition: winuser.h:803
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ApplicationPageWndProc(), ProcessPageOnNotify(), ProcessPageWndProc(), and TaskManagerWndProc().

◆ ProcessPage_OnEndProcessTree()

void ProcessPage_OnEndProcessTree ( void  )

Definition at line 146 of file endproc.c.

147{
148 DWORD dwProcessId;
150 WCHAR szTitle[256];
151 WCHAR strErrorText[260];
152
153 dwProcessId = GetSelectedProcessId();
154
155 if (dwProcessId == 0)
156 return;
157
159
160 /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
162 {
164 LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
167 return;
168 }
169
170 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
173 {
175 return;
176 }
177
178 if (!hProcess)
179 {
180 GetLastErrorText(strErrorText, 260);
183 return;
184 }
185
186 if (!ShutdownProcessTree(hProcess, dwProcessId))
187 {
188 GetLastErrorText(strErrorText, 260);
191 }
192
194}
BOOL ShutdownProcessTree(HANDLE hParentProcess, DWORD dwParentPID)
Definition: endproc.c:131

Referenced by TaskManagerWndProc().

◆ ShutdownProcessTree()

BOOL ShutdownProcessTree ( HANDLE  hParentProcess,
DWORD  dwParentPID 
)

Definition at line 131 of file endproc.c.

132{
134 BOOL bResult;
135
136 if (!hSnapshot)
137 {
138 return FALSE;
139 }
140
141 bResult = ShutdownProcessTreeHelper(hSnapshot, hParentProcess, dwParentPID);
142 CloseHandle(hSnapshot);
143 return bResult;
144}
HANDLE WINAPI CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID)
Definition: toolhelp.c:1255
BOOL ShutdownProcessTreeHelper(HANDLE hSnapshot, HANDLE hParentProcess, DWORD dwParentPID)
Definition: endproc.c:95
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TH32CS_SNAPPROCESS
Definition: tlhelp32.h:26

Referenced by ProcessPage_OnEndProcessTree().

◆ ShutdownProcessTreeHelper()

BOOL ShutdownProcessTreeHelper ( HANDLE  hSnapshot,
HANDLE  hParentProcess,
DWORD  dwParentPID 
)

Definition at line 95 of file endproc.c.

96{
97 HANDLE hChildHandle;
98 PROCESSENTRY32W ProcessEntry = {0};
99 ProcessEntry.dwSize = sizeof(ProcessEntry);
100
101 if (Process32FirstW(hSnapshot, &ProcessEntry))
102 {
103 do
104 {
105 if (ProcessEntry.th32ParentProcessID == dwParentPID)
106 {
108 FALSE,
109 ProcessEntry.th32ProcessID);
110 if (!hChildHandle || IsCriticalProcess(hChildHandle))
111 {
112 if (hChildHandle)
113 {
114 CloseHandle(hChildHandle);
115 }
116 continue;
117 }
118 if (!ShutdownProcessTreeHelper(hSnapshot, hChildHandle, ProcessEntry.th32ProcessID))
119 {
120 CloseHandle(hChildHandle);
121 return FALSE;
122 }
123 CloseHandle(hChildHandle);
124 }
125 } while (Process32NextW(hSnapshot, &ProcessEntry));
126 }
127
128 return TerminateProcess(hParentProcess, 0);
129}
BOOL WINAPI Process32NextW(HANDLE hSnapshot, LPPROCESSENTRY32W lppe)
Definition: toolhelp.c:1073
BOOL WINAPI Process32FirstW(HANDLE hSnapshot, LPPROCESSENTRY32W lppe)
Definition: toolhelp.c:984
DWORD th32ParentProcessID
Definition: tlhelp32.h:55
DWORD th32ProcessID
Definition: tlhelp32.h:51

Referenced by ShutdownProcessTree(), and ShutdownProcessTreeHelper().