ReactOS  0.4.12-dev-102-g4b7f1e0
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)
 
void ProcessPage_OnEndProcessTree (void)
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 27 of file endproc.c.

Function Documentation

◆ IsCriticalProcess()

BOOL IsCriticalProcess ( HANDLE  hProcess)

Definition at line 83 of file endproc.c.

Referenced by ProcessPage_OnEndProcess(), and ProcessPage_OnEndProcessTree().

84 {
86  ULONG BreakOnTermination;
87 
88  /* return early if the process handle does not exist */
89  if (!hProcess)
90  return FALSE;
91 
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.
94 
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> */
97 
98  status = NtQueryInformationProcess(hProcess,
100  &BreakOnTermination,
101  sizeof(ULONG),
102  NULL);
103 
104  if (NT_SUCCESS(status) && BreakOnTermination)
105  return TRUE;
106 
107  return FALSE;
108 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31

◆ ProcessPage_OnEndProcess()

void ProcessPage_OnEndProcess ( void  )

Definition at line 30 of file endproc.c.

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

31 {
32  DWORD dwProcessId;
34  WCHAR szTitle[256];
35  WCHAR strErrorText[260];
36 
37  dwProcessId = GetSelectedProcessId();
38 
39  if (dwProcessId == 0)
40  return;
41 
43 
44  /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
45  if (hProcess && IsCriticalProcess(hProcess))
46  {
48  LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
49  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONWARNING|MB_TOPMOST);
50  CloseHandle(hProcess);
51  return;
52  }
53 
54  /* if this is a standard process just ask for confirmation before doing it */
55  LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
57  if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING|MB_TOPMOST) != IDYES)
58  {
59  if (hProcess) CloseHandle(hProcess);
60  return;
61  }
62 
63  /* no such process or not enough privileges to open its token */
64  if (!hProcess)
65  {
66  GetLastErrorText(strErrorText, 260);
68  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP|MB_TOPMOST);
69  return;
70  }
71 
72  /* try to kill it, and notify the user if didn't work */
73  if (!TerminateProcess(hProcess, 1))
74  {
75  GetLastErrorText(strErrorText, 260);
77  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP|MB_TOPMOST);
78  }
79 
80  CloseHandle(hProcess);
81 }
DWORD GetSelectedProcessId(void)
Definition: procpage.c:99
#define CloseHandle
Definition: compat.h:398
#define IDYES
Definition: winuser.h:829
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define MB_ICONSTOP
Definition: winuser.h:797
#define MB_TOPMOST
Definition: winuser.h:819
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MB_ICONWARNING
Definition: winuser.h:780
#define MB_YESNO
Definition: winuser.h:811
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
unsigned long DWORD
Definition: ntddk_ex.h:95
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:36
HWND hMainWnd
Definition: magnifier.c:33
#define IDS_MSG_UNABLETERMINATEPRO
Definition: resource.h:248
#define IDS_MSG_TASKMGRWARNING
Definition: resource.h:246
BOOL IsCriticalProcess(HANDLE hProcess)
Definition: endproc.c:83
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1257
HINSTANCE hInst
Definition: dxdiag.c:13
#define PROCESS_TERMINATE
Definition: pstypes.h:149
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1562
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1152
#define MB_OK
Definition: winuser.h:784
#define IDS_MSG_CLOSESYSTEMPROCESS
Definition: resource.h:252
#define IDS_MSG_WARNINGTERMINATING
Definition: resource.h:247

◆ ProcessPage_OnEndProcessTree()

void ProcessPage_OnEndProcessTree ( void  )

Definition at line 110 of file endproc.c.

Referenced by TaskManagerWndProc().

111 {
112  DWORD dwProcessId;
114  WCHAR szTitle[256];
115  WCHAR strErrorText[260];
116 
117  dwProcessId = GetSelectedProcessId();
118 
119  if (dwProcessId == 0)
120  return;
121 
122  hProcess = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
123 
124  /* forbid killing system processes even if we have privileges -- sigh, windows kludge! */
125  if (hProcess && IsCriticalProcess(hProcess))
126  {
128  LoadStringW(hInst, IDS_MSG_CLOSESYSTEMPROCESS, strErrorText, 256);
129  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONWARNING|MB_TOPMOST);
130  CloseHandle(hProcess);
131  return;
132  }
133 
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)
137  {
138  if (hProcess) CloseHandle(hProcess);
139  return;
140  }
141 
142  if (!hProcess)
143  {
144  GetLastErrorText(strErrorText, 260);
146  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
147  return;
148  }
149 
150  if (!TerminateProcess(hProcess, 0))
151  {
152  GetLastErrorText(strErrorText, 260);
154  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
155  }
156 
157  CloseHandle(hProcess);
158 }
DWORD GetSelectedProcessId(void)
Definition: procpage.c:99
#define CloseHandle
Definition: compat.h:398
#define IDYES
Definition: winuser.h:829
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define MB_ICONSTOP
Definition: winuser.h:797
#define MB_TOPMOST
Definition: winuser.h:819
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MB_ICONWARNING
Definition: winuser.h:780
#define MB_YESNO
Definition: winuser.h:811
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
unsigned long DWORD
Definition: ntddk_ex.h:95
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:36
HWND hMainWnd
Definition: magnifier.c:33
#define IDS_MSG_UNABLETERMINATEPRO
Definition: resource.h:248
#define IDS_MSG_TASKMGRWARNING
Definition: resource.h:246
BOOL IsCriticalProcess(HANDLE hProcess)
Definition: endproc.c:83
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1257
HINSTANCE hInst
Definition: dxdiag.c:13
#define PROCESS_TERMINATE
Definition: pstypes.h:149
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1562
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1152
#define MB_OK
Definition: winuser.h:784
#define IDS_MSG_CLOSESYSTEMPROCESS
Definition: resource.h:252
#define IDS_MSG_WARNINGTERMINATING
Definition: resource.h:247