taskkill: Implement forcible termination by process identifier.
This commit is contained in:
parent
1ef5affbf3
commit
6cfeeed0df
|
@ -33,6 +33,8 @@ STRINGTABLE
|
||||||
STRING_MUTUAL_EXCLUSIVE, "Error: Options /im and /pid are mutually exclusive.\n"
|
STRING_MUTUAL_EXCLUSIVE, "Error: Options /im and /pid are mutually exclusive.\n"
|
||||||
STRING_CLOSE_PID_SEARCH, "Close message sent to top-level windows of process with PID %u.\n"
|
STRING_CLOSE_PID_SEARCH, "Close message sent to top-level windows of process with PID %u.\n"
|
||||||
STRING_CLOSE_PROC_SRCH, "Close message sent to top-level windows of process \"%s\" with PID %u.\n"
|
STRING_CLOSE_PROC_SRCH, "Close message sent to top-level windows of process \"%s\" with PID %u.\n"
|
||||||
|
STRING_TERM_PID_SEARCH, "Process with PID %u was forcibly terminated.\n"
|
||||||
STRING_SEARCH_FAILED, "Error: Could not find process \"%s\".\n"
|
STRING_SEARCH_FAILED, "Error: Could not find process \"%s\".\n"
|
||||||
STRING_ENUM_FAILED, "Error: Unable to enumerate the process list.\n"
|
STRING_ENUM_FAILED, "Error: Unable to enumerate the process list.\n"
|
||||||
|
STRING_TERMINATE_FAILED, "Error: Unable to terminate process \"%s\".\n"
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,6 +278,57 @@ static int send_close_messages(void)
|
||||||
return status_code;
|
return status_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int terminate_processes(void)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
int status_code = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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
|
||||||
|
WINE_FIXME("Forcible process termination by name is not implemented\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return status_code;
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL add_to_task_list(WCHAR *name)
|
static BOOL add_to_task_list(WCHAR *name)
|
||||||
{
|
{
|
||||||
static unsigned int list_size = 16;
|
static unsigned int list_size = 16;
|
||||||
|
@ -389,7 +440,7 @@ int wmain(int argc, WCHAR *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force_termination)
|
if (force_termination)
|
||||||
WINE_FIXME("Forced termination is not implemented\n");
|
status_code = terminate_processes();
|
||||||
else
|
else
|
||||||
status_code = send_close_messages();
|
status_code = send_close_messages();
|
||||||
|
|
||||||
|
|
|
@ -29,5 +29,7 @@
|
||||||
#define STRING_MUTUAL_EXCLUSIVE 106
|
#define STRING_MUTUAL_EXCLUSIVE 106
|
||||||
#define STRING_CLOSE_PID_SEARCH 107
|
#define STRING_CLOSE_PID_SEARCH 107
|
||||||
#define STRING_CLOSE_PROC_SRCH 108
|
#define STRING_CLOSE_PROC_SRCH 108
|
||||||
#define STRING_SEARCH_FAILED 109
|
#define STRING_TERM_PID_SEARCH 109
|
||||||
#define STRING_ENUM_FAILED 110
|
#define STRING_SEARCH_FAILED 110
|
||||||
|
#define STRING_ENUM_FAILED 111
|
||||||
|
#define STRING_TERMINATE_FAILED 112
|
||||||
|
|
Loading…
Reference in New Issue