ReactOS  0.4.14-dev-1296-g56aa513
taskkill.c File Reference
#include <stdlib.h>
#include <windows.h>
#include <psapi.h>
#include <wine/debug.h>
#include <wine/unicode.h>
#include "taskkill.h"
Include dependency graph for taskkill.c:

Go to the source code of this file.

Classes

struct  pid_close_info
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (taskkill)
 
static int taskkill_vprintfW (const WCHAR *msg, __ms_va_list va_args)
 
static int WINAPIV taskkill_printfW (const WCHAR *msg,...)
 
static int WINAPIV taskkill_message_printfW (int msg,...)
 
static int taskkill_message (int msg)
 
static BOOL CALLBACK pid_enum_proc (HWND hwnd, LPARAM lParam)
 
static DWORDenumerate_processes (DWORD *list_count)
 
static BOOL get_process_name_from_pid (DWORD pid, WCHAR *buf, DWORD chars)
 
static int send_close_messages (void)
 
static int terminate_processes (void)
 
static BOOL add_to_task_list (WCHAR *name)
 
static BOOL process_arguments (int argc, WCHAR *argv[])
 
int wmain (int argc, WCHAR *argv[])
 

Variables

static BOOL force_termination = FALSE
 
static WCHAR ** task_list
 
static unsigned int task_count
 

Function Documentation

◆ add_to_task_list()

static BOOL add_to_task_list ( WCHAR name)
static

Definition at line 488 of file taskkill.c.

489 {
490  static unsigned int list_size = 16;
491 
492  if (!task_list)
493  {
495  list_size * sizeof(*task_list));
496  if (!task_list)
497  return FALSE;
498  }
499  else if (task_count == list_size)
500  {
501  void *realloc_list;
502 
503  list_size *= 2;
504  realloc_list = HeapReAlloc(GetProcessHeap(), 0, task_list,
505  list_size * sizeof(*task_list));
506  if (!realloc_list)
507  return FALSE;
508 
509  task_list = realloc_list;
510  }
511 
513  return TRUE;
514 }
#define TRUE
Definition: types.h:120
static WCHAR ** task_list
Definition: taskkill.c:35
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define HeapReAlloc
Definition: compat.h:401
static unsigned int task_count
Definition: taskkill.c:36
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by process_arguments().

◆ enumerate_processes()

static DWORD* enumerate_processes ( DWORD list_count)
static

Definition at line 152 of file taskkill.c.

153 {
154  DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
155 
156  pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
157  if (!pid_list)
158  return NULL;
159 
160  for (;;)
161  {
162  DWORD *realloc_list;
163 
164  if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
165  {
166  HeapFree(GetProcessHeap(), 0, pid_list);
167  return NULL;
168  }
169 
170  /* EnumProcesses can't signal an insufficient buffer condition, so the
171  * only way to possibly determine whether a larger buffer is required
172  * is to see whether the written number of bytes is the same as the
173  * buffer size. If so, the buffer will be reallocated to twice the
174  * size. */
175  if (alloc_bytes != needed_bytes)
176  break;
177 
178  alloc_bytes *= 2;
179  realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
180  if (!realloc_list)
181  {
182  HeapFree(GetProcessHeap(), 0, pid_list);
183  return NULL;
184  }
185  pid_list = realloc_list;
186  }
187 
188  *list_count = needed_bytes / sizeof(*pid_list);
189  return pid_list;
190 }
__WINE_SERVER_LIST_INLINE unsigned int list_count(const struct list *list)
Definition: list.h:155
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI EnumProcesses(DWORD *lpidProcess, DWORD cb, LPDWORD lpcbNeeded)
Definition: psapi.c:458
#define HeapReAlloc
Definition: compat.h:401
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by send_close_messages(), and terminate_processes().

◆ get_process_name_from_pid()

static BOOL get_process_name_from_pid ( DWORD  pid,
WCHAR buf,
DWORD  chars 
)
static

Definition at line 192 of file taskkill.c.

193 {
194  HANDLE process;
195  HMODULE module;
196  DWORD required_size;
197 
199  if (!process)
200  return FALSE;
201 
202  if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
203  {
205  return FALSE;
206  }
207 
208  if (!GetModuleBaseNameW(process, module, buf, chars))
209  {
211  return FALSE;
212  }
213 
215  return TRUE;
216 }
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
HMODULE module
Definition: main.cpp:47
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static HANDLE process
Definition: process.c:76
DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
Definition: psapi.c:930
BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
Definition: psapi.c:542
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define PROCESS_VM_READ
Definition: pstypes.h:153

Referenced by send_close_messages(), and terminate_processes().

◆ pid_enum_proc()

static BOOL CALLBACK pid_enum_proc ( HWND  hwnd,
LPARAM  lParam 
)
static

Definition at line 136 of file taskkill.c.

137 {
138  struct pid_close_info *info = (struct pid_close_info *)lParam;
139  DWORD hwnd_pid;
140 
141  GetWindowThreadProcessId(hwnd, &hwnd_pid);
142 
143  if (hwnd_pid == info->pid)
144  {
145  PostMessageW(hwnd, WM_CLOSE, 0, 0);
146  info->found = TRUE;
147  }
148 
149  return TRUE;
150 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
#define WM_CLOSE
Definition: winuser.h:1603
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LPARAM lParam
Definition: combotst.c:139

Referenced by send_close_messages(), and terminate_processes().

◆ process_arguments()

static BOOL process_arguments ( int  argc,
WCHAR argv[] 
)
static

Definition at line 659 of file taskkill.c.

660 {
661  static const WCHAR opForceTerminate[] = {'f',0};
662  static const WCHAR opImage[] = {'i','m',0};
663  static const WCHAR opPID[] = {'p','i','d',0};
664  static const WCHAR opHelp[] = {'?',0};
665  static const WCHAR opTerminateChildren[] = {'t',0};
666 
667  if (argc > 1)
668  {
669  int i;
670  WCHAR *argdata;
671  BOOL has_im = FALSE, has_pid = FALSE;
672 
673  /* Only the lone help option is recognized. */
674  if (argc == 2)
675  {
676  argdata = argv[1];
677  if ((*argdata == '/' || *argdata == '-') && !strcmpW(opHelp, argdata + 1))
678  {
680  exit(0);
681  }
682  }
683 
684  for (i = 1; i < argc; i++)
685  {
686  BOOL got_im = FALSE, got_pid = FALSE;
687 
688  argdata = argv[i];
689  if (*argdata != '/' && *argdata != '-')
690  goto invalid;
691  argdata++;
692 
693  if (!strcmpiW(opTerminateChildren, argdata))
694  WINE_FIXME("argument T not supported\n");
695  if (!strcmpiW(opForceTerminate, argdata))
697  /* Options /IM and /PID appear to behave identically, except for
698  * the fact that they cannot be specified at the same time. */
699  else if ((got_im = !strcmpiW(opImage, argdata)) ||
700  (got_pid = !strcmpiW(opPID, argdata)))
701  {
702  if (!argv[i + 1])
703  {
706  return FALSE;
707  }
708 
709  if (got_im) has_im = TRUE;
710  if (got_pid) has_pid = TRUE;
711 
712  if (has_im && has_pid)
713  {
716  return FALSE;
717  }
718 
719  if (!add_to_task_list(argv[i + 1]))
720  return FALSE;
721  i++;
722  }
723  else
724  {
725  invalid:
728  return FALSE;
729  }
730  }
731  }
732  else
733  {
736  return FALSE;
737  }
738 
739  return TRUE;
740 }
static const WCHAR invalid[]
Definition: assoc.c:39
static int argc
Definition: ServiceArgs.c:12
#define STRING_USAGE
Definition: resource.h:26
#define TRUE
Definition: types.h:120
static BOOL force_termination
Definition: taskkill.c:33
#define argv
Definition: mplay32.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define STRING_MISSING_PARAM
Definition: taskkill.h:28
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STRING_MISSING_OPTION
Definition: taskkill.h:27
static int taskkill_message(int msg)
Definition: taskkill.c:125
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL add_to_task_list(WCHAR *name)
Definition: taskkill.c:488
#define strcmpiW(s1, s2)
Definition: unicode.h:39
static int WINAPIV taskkill_message_printfW(int msg,...)
Definition: taskkill.c:110
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
#define STRING_INVALID_OPTION
Definition: resource.h:53
void exit(int exitcode)
Definition: _exit.c:33
#define STRING_MUTUAL_EXCLUSIVE
Definition: taskkill.h:29
#define WINE_FIXME
Definition: debug.h:365

Referenced by wmain().

◆ send_close_messages()

static int send_close_messages ( void  )
static

Definition at line 235 of file taskkill.c.

236 {
237  DWORD *pid_list, pid_list_size;
238  DWORD self_pid = GetCurrentProcessId();
239  unsigned int i;
240  int status_code = 0;
241 
242  pid_list = enumerate_processes(&pid_list_size);
243  if (!pid_list)
244  {
246  return 1;
247  }
248 
249  for (i = 0; i < task_count; i++)
250  {
251  WCHAR *p = task_list[i];
252  BOOL is_numeric = TRUE;
253 
254  /* Determine whether the string is not numeric. */
255  while (*p)
256  {
257  if (!isdigitW(*p++))
258  {
259  is_numeric = FALSE;
260  break;
261  }
262  }
263 
264  if (is_numeric)
265  {
266  DWORD pid = atoiW(task_list[i]);
267  struct pid_close_info info = { pid };
268 
269  if (pid == self_pid)
270  {
272  status_code = 1;
273  continue;
274  }
275 
277  if (info.found)
279  else
280  {
282  status_code = 128;
283  }
284  }
285  else
286  {
287  DWORD index;
288  BOOL found_process = FALSE;
289 
290  for (index = 0; index < pid_list_size; index++)
291  {
292  WCHAR process_name[MAX_PATH];
293 
294  if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
295  !strcmpiW(process_name, task_list[i]))
296  {
297  struct pid_close_info info = { pid_list[index] };
298 
299  found_process = TRUE;
300  if (pid_list[index] == self_pid)
301  {
303  status_code = 1;
304  continue;
305  }
306 
308  taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
309  }
310  }
311 
312  if (!found_process)
313  {
315  status_code = 128;
316  }
317  }
318  }
319 
320  HeapFree(GetProcessHeap(), 0, pid_list);
321  return status_code;
322 }
#define STRING_CLOSE_PID_SEARCH
Definition: taskkill.h:30
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
#define STRING_CLOSE_PROC_SRCH
Definition: taskkill.h:31
#define TRUE
Definition: types.h:120
#define STRING_ENUM_FAILED
Definition: taskkill.h:35
static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
Definition: taskkill.c:192
struct status_code status_code
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG_PTR LPARAM
Definition: windef.h:208
GLuint index
Definition: glext.h:6031
static WCHAR ** task_list
Definition: taskkill.c:35
#define STRING_SELF_TERMINATION
Definition: taskkill.h:37
#define GetProcessHeap()
Definition: compat.h:403
static int taskkill_message(int msg)
Definition: taskkill.c:125
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC, _In_ LPARAM)
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD * enumerate_processes(DWORD *list_count)
Definition: taskkill.c:152
#define index(s, c)
Definition: various.h:29
#define strcmpiW(s1, s2)
Definition: unicode.h:39
static BOOL CALLBACK pid_enum_proc(HWND hwnd, LPARAM lParam)
Definition: taskkill.c:136
static int WINAPIV taskkill_message_printfW(int msg,...)
Definition: taskkill.c:110
#define STRING_SEARCH_FAILED
Definition: taskkill.h:34
WINE_UNICODE_INLINE int isdigitW(WCHAR wc)
Definition: unicode.h:170
GLfloat GLfloat p
Definition: glext.h:8902
static unsigned int task_count
Definition: taskkill.c:36
#define HeapFree(x, y, z)
Definition: compat.h:402
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
WINE_UNICODE_INLINE int atoiW(const WCHAR *str)
Definition: unicode.h:315

Referenced by wmain().

◆ taskkill_message()

static int taskkill_message ( int  msg)
static

Definition at line 125 of file taskkill.c.

126 {
127  static const WCHAR formatW[] = {'%','1',0};
128  WCHAR msg_buffer[8192];
129 
130  LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
131 
132  return taskkill_printfW(formatW, msg_buffer);
133 }
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
smooth NULL
Definition: ftsmooth.c:416
static int WINAPIV taskkill_printfW(const WCHAR *msg,...)
Definition: taskkill.c:98
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAY_SIZE(a)
Definition: main.h:24
#define msg(x)
Definition: auth_time.c:54
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838

Referenced by process_arguments(), send_close_messages(), and terminate_processes().

◆ taskkill_message_printfW()

static int WINAPIV taskkill_message_printfW ( int  msg,
  ... 
)
static

Definition at line 110 of file taskkill.c.

111 {
112  __ms_va_list va_args;
113  WCHAR msg_buffer[8192];
114  int len;
115 
116  LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
117 
118  __ms_va_start(va_args, msg);
119  len = taskkill_vprintfW(msg_buffer, va_args);
120  __ms_va_end(va_args);
121 
122  return len;
123 }
static static const char __ms_va_list
Definition: printf.c:76
static int taskkill_vprintfW(const WCHAR *msg, __ms_va_list va_args)
Definition: taskkill.c:64
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLsizei len
Definition: glext.h:6722
#define ARRAY_SIZE(a)
Definition: main.h:24
#define __ms_va_end(list)
Definition: windef.h:458
#define msg(x)
Definition: auth_time.c:54
#define __ms_va_start(list, arg)
Definition: windef.h:457
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838

Referenced by process_arguments(), send_close_messages(), and terminate_processes().

◆ taskkill_printfW()

static int WINAPIV taskkill_printfW ( const WCHAR msg,
  ... 
)
static

Definition at line 98 of file taskkill.c.

99 {
100  __ms_va_list va_args;
101  int len;
102 
103  __ms_va_start(va_args, msg);
104  len = taskkill_vprintfW(msg, va_args);
105  __ms_va_end(va_args);
106 
107  return len;
108 }
static static const char __ms_va_list
Definition: printf.c:76
static int taskkill_vprintfW(const WCHAR *msg, __ms_va_list va_args)
Definition: taskkill.c:64
GLenum GLsizei len
Definition: glext.h:6722
#define __ms_va_end(list)
Definition: windef.h:458
#define msg(x)
Definition: auth_time.c:54
#define __ms_va_start(list, arg)
Definition: windef.h:457

Referenced by taskkill_message().

◆ taskkill_vprintfW()

static int taskkill_vprintfW ( const WCHAR msg,
__ms_va_list  va_args 
)
static

Definition at line 64 of file taskkill.c.

65 {
66  int wlen;
67  DWORD count, ret;
68  WCHAR msg_buffer[8192];
69 
70  wlen = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, msg_buffer,
71  ARRAY_SIZE(msg_buffer), &va_args);
72 
73  ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
74  if (!ret)
75  {
76  DWORD len;
77  char *msgA;
78 
79  /* On Windows WriteConsoleW() fails if the output is redirected. So fall
80  * back to WriteFile(), assuming the console encoding is still the right
81  * one in that case.
82  */
83  len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
84  NULL, 0, NULL, NULL);
85  msgA = HeapAlloc(GetProcessHeap(), 0, len);
86  if (!msgA)
87  return 0;
88 
89  WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
90  NULL, NULL);
92  HeapFree(GetProcessHeap(), 0, msgA);
93  }
94 
95  return count;
96 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define WideCharToMultiByte
Definition: compat.h:101
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1447
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2453
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define ARRAY_SIZE(a)
Definition: main.h:24
#define msg(x)
Definition: auth_time.c:54
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by taskkill_message_printfW(), and taskkill_printfW().

◆ terminate_processes()

static int terminate_processes ( void  )
static

Definition at line 329 of file taskkill.c.

331 {
332  DWORD *pid_list, pid_list_size;
333  DWORD self_pid = GetCurrentProcessId();
334  unsigned int i;
335  int status_code = 0;
336 
337  pid_list = enumerate_processes(&pid_list_size);
338  if (!pid_list)
339  {
341  return 1;
342  }
343 
344  for (i = 0; i < task_count; i++)
345  {
346  WCHAR *p = task_list[i];
347  BOOL is_numeric = TRUE;
348 
349  /* Determine whether the string is not numeric. */
350  while (*p)
351  {
352  if (!isdigitW(*p++))
353  {
354  is_numeric = FALSE;
355  break;
356  }
357  }
358 
359  if (is_numeric)
360  {
361  DWORD pid = atoiW(task_list[i]);
362 #ifndef __REACTOS__
363  HANDLE process;
364 #endif
365 
366  if (pid == self_pid)
367  {
369  status_code = 1;
370  continue;
371  }
372 
373 #ifdef __REACTOS__
374  if (force_termination)
375  {
376  HANDLE process;
377 #endif
379  if (!process)
380  {
382  status_code = 128;
383  continue;
384  }
385 
386  if (!TerminateProcess(process, 0))
387  {
389  status_code = 1;
391  continue;
392  }
393 
396 #ifdef __REACTOS__
397  }
398  else
399  {
400  struct pid_close_info info = { pid };
401 
403  if (info.found)
405  else
406  {
408  status_code = 128;
409  }
410  }
411 #endif
412  }
413  else
414  {
415  DWORD index;
416  BOOL found_process = FALSE;
417 
418  for (index = 0; index < pid_list_size; index++)
419  {
420  WCHAR process_name[MAX_PATH];
421 
422  if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
423  !strcmpiW(process_name, task_list[i]))
424  {
425 #ifdef __REACTOS__
426  found_process = TRUE;
427 #else
428  HANDLE process;
429 #endif
430 
431  if (pid_list[index] == self_pid)
432  {
434  status_code = 1;
435  continue;
436  }
437 
438 #ifdef __REACTOS__
439  if (force_termination)
440  {
441  HANDLE process;
442 #endif
444  if (!process)
445  {
447  status_code = 128;
448  continue;
449  }
450 
451  if (!TerminateProcess(process, 0))
452  {
454  status_code = 1;
456  continue;
457  }
458 
459 #ifndef __REACTOS__
460  found_process = TRUE;
461 #endif
464 #ifdef __REACTOS__
465  }
466  else
467  {
468  struct pid_close_info info = { pid_list[index] };
470  taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
471  }
472 #endif
473  }
474  }
475 
476  if (!found_process)
477  {
479  status_code = 128;
480  }
481  }
482  }
483 
484  HeapFree(GetProcessHeap(), 0, pid_list);
485  return status_code;
486 }
#define STRING_CLOSE_PID_SEARCH
Definition: taskkill.h:30
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
#define STRING_CLOSE_PROC_SRCH
Definition: taskkill.h:31
#define TRUE
Definition: types.h:120
static BOOL force_termination
Definition: taskkill.c:33
#define CloseHandle
Definition: compat.h:406
#define STRING_ENUM_FAILED
Definition: taskkill.h:35
static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
Definition: taskkill.c:192
#define STRING_TERM_PROC_SEARCH
Definition: taskkill.h:33
static HANDLE process
Definition: process.c:76
struct status_code status_code
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG_PTR LPARAM
Definition: windef.h:208
GLuint index
Definition: glext.h:6031
static WCHAR ** task_list
Definition: taskkill.c:35
#define STRING_SELF_TERMINATION
Definition: taskkill.h:37
#define GetProcessHeap()
Definition: compat.h:403
static int taskkill_message(int msg)
Definition: taskkill.c:125
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
BOOL WINAPI EnumWindows(_In_ WNDENUMPROC, _In_ LPARAM)
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD * enumerate_processes(DWORD *list_count)
Definition: taskkill.c:152
#define index(s, c)
Definition: various.h:29
#define STRING_TERMINATE_FAILED
Definition: taskkill.h:36
#define strcmpiW(s1, s2)
Definition: unicode.h:39
static BOOL CALLBACK pid_enum_proc(HWND hwnd, LPARAM lParam)
Definition: taskkill.c:136
static int WINAPIV taskkill_message_printfW(int msg,...)
Definition: taskkill.c:110
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define PROCESS_TERMINATE
Definition: pstypes.h:149
#define STRING_SEARCH_FAILED
Definition: taskkill.h:34
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
WINE_UNICODE_INLINE int isdigitW(WCHAR wc)
Definition: unicode.h:170
#define STRING_TERM_PID_SEARCH
Definition: taskkill.h:32
GLfloat GLfloat p
Definition: glext.h:8902
static unsigned int task_count
Definition: taskkill.c:36
#define HeapFree(x, y, z)
Definition: compat.h:402
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
WINE_UNICODE_INLINE int atoiW(const WCHAR *str)
Definition: unicode.h:315

Referenced by wmain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( taskkill  )

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 744 of file taskkill.c.

745 {
746  int status_code = 0;
747 
748  if (!process_arguments(argc, argv))
749  {
751  return 1;
752  }
753 
754 #ifdef __REACTOS__
756 #else
757  if (force_termination)
759  else
761 #endif
762 
764  return status_code;
765 }
static int argc
Definition: ServiceArgs.c:12
static BOOL force_termination
Definition: taskkill.c:33
static int terminate_processes(void)
Definition: taskkill.c:329
#define argv
Definition: mplay32.c:18
struct status_code status_code
static WCHAR ** task_list
Definition: taskkill.c:35
#define GetProcessHeap()
Definition: compat.h:403
static int send_close_messages(void)
Definition: taskkill.c:235
static BOOL process_arguments(int argc, WCHAR *argv[])
Definition: taskkill.c:659
#define HeapFree(x, y, z)
Definition: compat.h:402

Variable Documentation

◆ force_termination

BOOL force_termination = FALSE
static

Definition at line 33 of file taskkill.c.

Referenced by process_arguments(), terminate_processes(), and wmain().

◆ task_count

unsigned int task_count
static

Definition at line 36 of file taskkill.c.

Referenced by add_to_task_list(), send_close_messages(), and terminate_processes().

◆ task_list

WCHAR** task_list
static