2010-09-21 09:17:09 +02:00
|
|
|
/*
|
|
|
|
* Task termination utility
|
|
|
|
*
|
2010-09-21 09:17:26 +02:00
|
|
|
* Copyright 2008 Andrew Riedi
|
2010-09-21 09:17:09 +02:00
|
|
|
* Copyright 2010 Andrew Nguyen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <stdlib.h>
|
2010-09-21 09:17:09 +02:00
|
|
|
#include <windows.h>
|
2010-09-21 09:20:58 +02:00
|
|
|
#include <psapi.h>
|
2012-05-18 10:48:01 +02:00
|
|
|
#include <wine/debug.h>
|
2010-09-21 09:17:09 +02:00
|
|
|
#include <wine/unicode.h>
|
|
|
|
|
2010-09-21 09:17:26 +02:00
|
|
|
#include "taskkill.h"
|
|
|
|
|
2012-05-18 10:48:01 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(taskkill);
|
|
|
|
|
2013-10-01 23:33:54 +02:00
|
|
|
static BOOL force_termination = FALSE;
|
2010-09-21 09:17:09 +02:00
|
|
|
|
2010-10-01 13:38:41 +02:00
|
|
|
static WCHAR **task_list;
|
|
|
|
static unsigned int task_count;
|
2010-09-21 09:17:26 +02:00
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
struct pid_close_info
|
|
|
|
{
|
|
|
|
DWORD pid;
|
|
|
|
BOOL found;
|
|
|
|
};
|
|
|
|
|
2011-11-19 15:10:07 +01:00
|
|
|
static int taskkill_vprintfW(const WCHAR *msg, __ms_va_list va_args)
|
2010-09-21 09:17:26 +02:00
|
|
|
{
|
|
|
|
int wlen;
|
|
|
|
DWORD count, ret;
|
|
|
|
WCHAR msg_buffer[8192];
|
|
|
|
|
2011-11-19 15:10:07 +01:00
|
|
|
wlen = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, msg_buffer,
|
2018-07-24 00:01:28 +02:00
|
|
|
ARRAY_SIZE(msg_buffer), &va_args);
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
char *msgA;
|
|
|
|
|
2011-08-24 14:29:31 +02:00
|
|
|
/* On Windows WriteConsoleW() fails if the output is redirected. So fall
|
|
|
|
* back to WriteFile(), assuming the console encoding is still the right
|
|
|
|
* one in that case.
|
|
|
|
*/
|
2010-09-21 09:17:26 +02:00
|
|
|
len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
msgA = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!msgA)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
|
|
|
|
NULL, NULL);
|
|
|
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, msgA);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-11-02 10:22:10 +01:00
|
|
|
static int WINAPIV taskkill_printfW(const WCHAR *msg, ...)
|
2010-09-21 09:17:26 +02:00
|
|
|
{
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_list va_args;
|
2010-09-21 09:17:26 +02:00
|
|
|
int len;
|
|
|
|
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_start(va_args, msg);
|
2010-09-21 09:17:26 +02:00
|
|
|
len = taskkill_vprintfW(msg, va_args);
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_end(va_args);
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2017-11-02 10:22:10 +01:00
|
|
|
static int WINAPIV taskkill_message_printfW(int msg, ...)
|
2010-09-21 09:17:26 +02:00
|
|
|
{
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_list va_args;
|
2010-09-21 09:17:26 +02:00
|
|
|
WCHAR msg_buffer[8192];
|
|
|
|
int len;
|
|
|
|
|
2018-07-24 00:01:28 +02:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
|
2010-09-21 09:17:26 +02:00
|
|
|
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_start(va_args, msg);
|
2010-09-21 09:17:26 +02:00
|
|
|
len = taskkill_vprintfW(msg_buffer, va_args);
|
2011-11-19 15:10:07 +01:00
|
|
|
__ms_va_end(va_args);
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int taskkill_message(int msg)
|
|
|
|
{
|
2011-11-19 15:10:07 +01:00
|
|
|
static const WCHAR formatW[] = {'%','1',0};
|
2010-09-21 09:17:26 +02:00
|
|
|
WCHAR msg_buffer[8192];
|
|
|
|
|
2018-07-24 00:01:28 +02:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer));
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
return taskkill_printfW(formatW, msg_buffer);
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
/* Post WM_CLOSE to all top-level windows belonging to the process with specified PID. */
|
|
|
|
static BOOL CALLBACK pid_enum_proc(HWND hwnd, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct pid_close_info *info = (struct pid_close_info *)lParam;
|
|
|
|
DWORD hwnd_pid;
|
|
|
|
|
|
|
|
GetWindowThreadProcessId(hwnd, &hwnd_pid);
|
|
|
|
|
|
|
|
if (hwnd_pid == info->pid)
|
|
|
|
{
|
|
|
|
PostMessageW(hwnd, WM_CLOSE, 0, 0);
|
|
|
|
info->found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:20:58 +02:00
|
|
|
static DWORD *enumerate_processes(DWORD *list_count)
|
|
|
|
{
|
|
|
|
DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
|
|
|
|
|
|
|
|
pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
|
|
|
|
if (!pid_list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD *realloc_list;
|
|
|
|
|
|
|
|
if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pid_list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EnumProcesses can't signal an insufficient buffer condition, so the
|
|
|
|
* only way to possibly determine whether a larger buffer is required
|
|
|
|
* is to see whether the written number of bytes is the same as the
|
|
|
|
* buffer size. If so, the buffer will be reallocated to twice the
|
|
|
|
* size. */
|
|
|
|
if (alloc_bytes != needed_bytes)
|
|
|
|
break;
|
|
|
|
|
|
|
|
alloc_bytes *= 2;
|
|
|
|
realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
|
|
|
|
if (!realloc_list)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pid_list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pid_list = realloc_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
*list_count = needed_bytes / sizeof(*pid_list);
|
|
|
|
return pid_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
|
|
|
|
{
|
|
|
|
HANDLE process;
|
|
|
|
HMODULE module;
|
|
|
|
DWORD required_size;
|
|
|
|
|
|
|
|
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
|
|
|
|
if (!process)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
|
|
|
|
{
|
|
|
|
CloseHandle(process);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetModuleBaseNameW(process, module, buf, chars))
|
|
|
|
{
|
|
|
|
CloseHandle(process);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(process);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
/* The implemented task enumeration and termination behavior does not
|
|
|
|
* exactly match native behavior. On Windows:
|
|
|
|
*
|
|
|
|
* In the case of terminating by process name, specifying a particular
|
|
|
|
* process name more times than the number of running instances causes
|
|
|
|
* all instances to be terminated, but termination failure messages to
|
|
|
|
* be printed as many times as the difference between the specification
|
|
|
|
* quantity and the number of running instances.
|
|
|
|
*
|
|
|
|
* Successful terminations are all listed first in order, with failing
|
|
|
|
* terminations being listed at the end.
|
|
|
|
*
|
|
|
|
* A PID of zero causes taskkill to warn about the inability to terminate
|
|
|
|
* system processes. */
|
|
|
|
static int send_close_messages(void)
|
|
|
|
{
|
2010-09-21 09:20:58 +02:00
|
|
|
DWORD *pid_list, pid_list_size;
|
2010-10-11 12:13:43 +02:00
|
|
|
DWORD self_pid = GetCurrentProcessId();
|
2010-09-21 09:18:41 +02:00
|
|
|
unsigned int i;
|
|
|
|
int status_code = 0;
|
|
|
|
|
2010-09-21 09:20:58 +02:00
|
|
|
pid_list = enumerate_processes(&pid_list_size);
|
|
|
|
if (!pid_list)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_ENUM_FAILED);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
for (i = 0; i < task_count; i++)
|
|
|
|
{
|
|
|
|
WCHAR *p = task_list[i];
|
|
|
|
BOOL is_numeric = TRUE;
|
|
|
|
|
|
|
|
/* Determine whether the string is not numeric. */
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (!isdigitW(*p++))
|
|
|
|
{
|
|
|
|
is_numeric = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric)
|
|
|
|
{
|
|
|
|
DWORD pid = atoiW(task_list[i]);
|
|
|
|
struct pid_close_info info = { pid };
|
|
|
|
|
2010-10-11 12:13:43 +02:00
|
|
|
if (pid == self_pid)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_SELF_TERMINATION);
|
|
|
|
status_code = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
|
|
|
if (info.found)
|
|
|
|
taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
|
|
status_code = 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-09-21 09:20:58 +02:00
|
|
|
{
|
|
|
|
DWORD index;
|
|
|
|
BOOL found_process = FALSE;
|
|
|
|
|
|
|
|
for (index = 0; index < pid_list_size; index++)
|
|
|
|
{
|
|
|
|
WCHAR process_name[MAX_PATH];
|
|
|
|
|
|
|
|
if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
|
|
|
|
!strcmpiW(process_name, task_list[i]))
|
|
|
|
{
|
|
|
|
struct pid_close_info info = { pid_list[index] };
|
|
|
|
|
|
|
|
found_process = TRUE;
|
2010-10-11 12:13:43 +02:00
|
|
|
if (pid_list[index] == self_pid)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_SELF_TERMINATION);
|
|
|
|
status_code = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:20:58 +02:00
|
|
|
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
|
|
|
taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_process)
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
|
|
status_code = 128;
|
|
|
|
}
|
|
|
|
}
|
2010-09-21 09:18:41 +02:00
|
|
|
}
|
|
|
|
|
2010-09-21 09:20:58 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pid_list);
|
2010-09-21 09:18:41 +02:00
|
|
|
return status_code;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:21:14 +02:00
|
|
|
static int terminate_processes(void)
|
|
|
|
{
|
2010-09-21 09:21:23 +02:00
|
|
|
DWORD *pid_list, pid_list_size;
|
2010-10-11 12:13:43 +02:00
|
|
|
DWORD self_pid = GetCurrentProcessId();
|
2010-09-21 09:21:14 +02:00
|
|
|
unsigned int i;
|
|
|
|
int status_code = 0;
|
|
|
|
|
2010-09-21 09:21:23 +02:00
|
|
|
pid_list = enumerate_processes(&pid_list_size);
|
|
|
|
if (!pid_list)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_ENUM_FAILED);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:21:14 +02:00
|
|
|
for (i = 0; i < task_count; i++)
|
|
|
|
{
|
|
|
|
WCHAR *p = task_list[i];
|
|
|
|
BOOL is_numeric = TRUE;
|
|
|
|
|
|
|
|
/* Determine whether the string is not numeric. */
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (!isdigitW(*p++))
|
|
|
|
{
|
|
|
|
is_numeric = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric)
|
|
|
|
{
|
|
|
|
DWORD pid = atoiW(task_list[i]);
|
|
|
|
HANDLE process;
|
|
|
|
|
2010-10-11 12:13:43 +02:00
|
|
|
if (pid == self_pid)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_SELF_TERMINATION);
|
|
|
|
status_code = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:21:14 +02:00
|
|
|
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
|
|
status_code = 128;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TerminateProcess(process, 0))
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_TERMINATE_FAILED, task_list[i]);
|
|
|
|
status_code = 1;
|
|
|
|
CloseHandle(process);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
taskkill_message_printfW(STRING_TERM_PID_SEARCH, pid);
|
|
|
|
CloseHandle(process);
|
|
|
|
}
|
|
|
|
else
|
2010-09-21 09:21:23 +02:00
|
|
|
{
|
|
|
|
DWORD index;
|
|
|
|
BOOL found_process = FALSE;
|
|
|
|
|
|
|
|
for (index = 0; index < pid_list_size; index++)
|
|
|
|
{
|
|
|
|
WCHAR process_name[MAX_PATH];
|
|
|
|
|
|
|
|
if (get_process_name_from_pid(pid_list[index], process_name, MAX_PATH) &&
|
|
|
|
!strcmpiW(process_name, task_list[i]))
|
|
|
|
{
|
|
|
|
HANDLE process;
|
|
|
|
|
2010-10-11 12:13:43 +02:00
|
|
|
if (pid_list[index] == self_pid)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_SELF_TERMINATION);
|
|
|
|
status_code = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:21:23 +02:00
|
|
|
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
|
|
status_code = 128;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TerminateProcess(process, 0))
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_TERMINATE_FAILED, task_list[i]);
|
|
|
|
status_code = 1;
|
|
|
|
CloseHandle(process);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
found_process = TRUE;
|
|
|
|
taskkill_message_printfW(STRING_TERM_PROC_SEARCH, task_list[i], pid_list[index]);
|
|
|
|
CloseHandle(process);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_process)
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_SEARCH_FAILED, task_list[i]);
|
|
|
|
status_code = 128;
|
|
|
|
}
|
|
|
|
}
|
2010-09-21 09:21:14 +02:00
|
|
|
}
|
|
|
|
|
2010-09-21 09:21:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pid_list);
|
2010-09-21 09:21:14 +02:00
|
|
|
return status_code;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:17:26 +02:00
|
|
|
static BOOL add_to_task_list(WCHAR *name)
|
|
|
|
{
|
|
|
|
static unsigned int list_size = 16;
|
|
|
|
|
|
|
|
if (!task_list)
|
|
|
|
{
|
|
|
|
task_list = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
list_size * sizeof(*task_list));
|
|
|
|
if (!task_list)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (task_count == list_size)
|
|
|
|
{
|
|
|
|
void *realloc_list;
|
|
|
|
|
|
|
|
list_size *= 2;
|
|
|
|
realloc_list = HeapReAlloc(GetProcessHeap(), 0, task_list,
|
|
|
|
list_size * sizeof(*task_list));
|
|
|
|
if (!realloc_list)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
task_list = realloc_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
task_list[task_count++] = name;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME Argument processing does not match behavior observed on Windows.
|
|
|
|
* Stringent argument counting and processing is performed, and unrecognized
|
|
|
|
* options are detected as parameters when placed after options that accept one. */
|
|
|
|
static BOOL process_arguments(int argc, WCHAR *argv[])
|
|
|
|
{
|
2014-01-22 00:24:54 +01:00
|
|
|
static const WCHAR opForceTerminate[] = {'f',0};
|
|
|
|
static const WCHAR opImage[] = {'i','m',0};
|
|
|
|
static const WCHAR opPID[] = {'p','i','d',0};
|
|
|
|
static const WCHAR opHelp[] = {'?',0};
|
|
|
|
static const WCHAR opTerminateChildren[] = {'t',0};
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
{
|
|
|
|
int i;
|
2014-01-22 00:24:54 +01:00
|
|
|
WCHAR *argdata;
|
2013-10-01 23:33:54 +02:00
|
|
|
BOOL has_im = FALSE, has_pid = FALSE;
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
/* Only the lone help option is recognized. */
|
2014-01-22 00:24:54 +01:00
|
|
|
if (argc == 2)
|
2010-09-21 09:17:26 +02:00
|
|
|
{
|
2014-01-22 00:24:54 +01:00
|
|
|
argdata = argv[1];
|
|
|
|
if ((*argdata == '/' || *argdata == '-') && !strcmpW(opHelp, argdata + 1))
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_USAGE);
|
|
|
|
exit(0);
|
|
|
|
}
|
2010-09-21 09:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2014-02-22 12:22:34 +01:00
|
|
|
BOOL got_im = FALSE, got_pid = FALSE;
|
2010-09-21 09:17:26 +02:00
|
|
|
|
2014-01-22 00:24:54 +01:00
|
|
|
argdata = argv[i];
|
|
|
|
if (*argdata != '/' && *argdata != '-')
|
|
|
|
goto invalid;
|
|
|
|
argdata++;
|
|
|
|
|
|
|
|
if (!strcmpiW(opTerminateChildren, argdata))
|
|
|
|
WINE_FIXME("argument T not supported\n");
|
|
|
|
if (!strcmpiW(opForceTerminate, argdata))
|
2013-10-01 23:33:54 +02:00
|
|
|
force_termination = TRUE;
|
2010-09-21 09:17:26 +02:00
|
|
|
/* Options /IM and /PID appear to behave identically, except for
|
|
|
|
* the fact that they cannot be specified at the same time. */
|
2014-01-22 00:24:54 +01:00
|
|
|
else if ((got_im = !strcmpiW(opImage, argdata)) ||
|
|
|
|
(got_pid = !strcmpiW(opPID, argdata)))
|
2010-09-21 09:17:26 +02:00
|
|
|
{
|
|
|
|
if (!argv[i + 1])
|
|
|
|
{
|
|
|
|
taskkill_message_printfW(STRING_MISSING_PARAM, argv[i]);
|
|
|
|
taskkill_message(STRING_USAGE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:33:54 +02:00
|
|
|
if (got_im) has_im = TRUE;
|
|
|
|
if (got_pid) has_pid = TRUE;
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
if (has_im && has_pid)
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_MUTUAL_EXCLUSIVE);
|
|
|
|
taskkill_message(STRING_USAGE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!add_to_task_list(argv[i + 1]))
|
|
|
|
return FALSE;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-22 00:24:54 +01:00
|
|
|
invalid:
|
2010-09-21 09:17:26 +02:00
|
|
|
taskkill_message(STRING_INVALID_OPTION);
|
|
|
|
taskkill_message(STRING_USAGE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
taskkill_message(STRING_MISSING_OPTION);
|
|
|
|
taskkill_message(STRING_USAGE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:17:09 +02:00
|
|
|
int wmain(int argc, WCHAR *argv[])
|
|
|
|
{
|
2010-09-21 09:18:41 +02:00
|
|
|
int status_code = 0;
|
|
|
|
|
2010-09-21 09:17:26 +02:00
|
|
|
if (!process_arguments(argc, argv))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, task_list);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-21 09:18:41 +02:00
|
|
|
if (force_termination)
|
2010-09-21 09:21:14 +02:00
|
|
|
status_code = terminate_processes();
|
2010-09-21 09:18:41 +02:00
|
|
|
else
|
|
|
|
status_code = send_close_messages();
|
2010-09-21 09:17:26 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, task_list);
|
2010-09-21 09:18:41 +02:00
|
|
|
return status_code;
|
2010-09-21 09:17:09 +02:00
|
|
|
}
|