Last active
January 23, 2017 15:21
-
-
Save SYZYGY-DEV333/b926bc1f95656201c7bd7581ffee4e11 to your computer and use it in GitHub Desktop.
Task-killer: a command-line Windows task manager/task killer in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
// Copyright (c) 2016, SYZYGY-DEV333 | |
// All rights reserved. | |
// Licensed under SPL 1.0 [splicense.pen.io] | |
int menu(); | |
void lista_processos(); | |
void mata_processo_nome(); | |
void mata_processo_PID(); | |
void mata_processo(char *comando); | |
FILE *arq; | |
int op, i; | |
char processo[1000], cmd_kill[2000], op_menu[2000]; | |
int main() { | |
while (menu() == 1); | |
system("pause"); | |
return 0; | |
} | |
void lista_processos() { | |
char c; | |
system("cls"); | |
arq = system("tasklist"); | |
while( (c = fgetc(arq))!= EOF ) | |
printf("%c", c); | |
fclose(arq); | |
} | |
int menu() { | |
int valida = 1; | |
printf("\n> 1 | List Process"); | |
printf("\n> 2 | Kill Process by PID"); | |
printf("\n> 3 | Kill Process by name"); | |
printf("\n> 4 | Clear screen"); | |
printf("\n> 0 | EXIT"); | |
printf("\n\n> Your Option is: "); | |
do { | |
valida = 1; | |
scanf("%s", op_menu); | |
for (i = 0; op_menu[i] != '\0'; i++) | |
if( isdigit(op_menu[i]) == 0 ) | |
valida = 0; | |
if (valida == 0) | |
printf("\nOnly positive, numbers: "); | |
} while (valida != 1); | |
op = atoi(op_menu); | |
if (op == 0) | |
return 0; | |
else if (op == 1) | |
lista_processos(); | |
else if (op == 2) | |
mata_processo_PID(); | |
else if (op == 3) | |
mata_processo_nome(); | |
else | |
system("cls"); | |
return 1; | |
} | |
void mata_processo(char *comando) { | |
printf("\nexecuta: %s", comando); | |
} | |
void mata_processo_nome() { | |
printf("\nName of process(example: \"chrome.exe\"): "); | |
scanf("%s", processo); | |
sprintf(cmd_kill, "TASKKILL /F /IM \"%s\"", processo); | |
system("cls"); | |
system(cmd_kill); | |
} | |
void mata_processo_PID() { | |
printf("\nPID of process(example: \"1050\"): "); | |
scanf("%s", processo); | |
sprintf(cmd_kill, "TASKKILL /F /PID \"%s\"", processo); | |
system("cls"); | |
system(cmd_kill); | |
} |
I compiled this with Codeblocks/GCC on Windows.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Licence
Copyright (c) 2016, SYZYGY-DEV333
All rights reserved.
Redistribution and use in source or compiled forms, with or
without modification, are permitted provided that the following
conditions are met:
Redistributions of source code must retain the above
copyright notice this list of conditions and the following
disclaimer.
Redistributions in compiled form must reproduce the
above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution. Compiled forms
are any forms of the software other than source form.
Neither the name of the [organization] nor the names of
its contributors may be used to endorse or promote
products derived from this software without specific prior
written permission.
Unless explicitly stated otherwise, contributions submitted
for inclusion in this software must be under the terms and
conditions of this License, without any further terms or
conditions.
Contributers to this software grant the [organization] a
permanent patent grant to use, make, sell, and otherwise
transfer this software, where such license applies only to
those patent claims licensable by such contributor that are
necessarily infringed by their contributions alone or by
combination of their contributions with the Work to which
such contributions was submitted.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.