markiemrboo Posted December 31, 2005 Posted December 31, 2005 http://forums.overclockersclub.com/Would_A...ppl-t59981.html Here you go chappy.. it's not a Window like you asked for though... just a simple console app, run it and it'll try and kill whatever's in the list. You can download the binary from http://bone.servebeer.com/EndTasks.zip Should be pretty self explanatory, stick the name of the processes you want to kill (get it from task manager) in KillList.txt and run the program. Quite a neat idea if you're really that worried about processes running while gaming (I couldn't give a rats what's running in the background while gaming personally lol) Warning: Incoming bad coding #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <psapi.h> #include <assert.h> int main(void) { DWORD p[1024], count; int numP, lines = 0, killed = 0; HANDLE ph; FILE *fp; char fbuf[1024], **pKillList; /* * get process kill list info */ /* open kill list file */ fp = fopen("KillList.txt", "r"); if (fp == NULL) { perror("fopen (KillList.txt)"); system("pause"); return 1; } /* get a line count for size of array */ while (!feof(fp)) { if (fgets(fbuf, 1024, fp) != NULL) { lines++; } } fclose(fp); /* the file must have at least one process to kill in it */ if (lines < 1) { fprintf(stderr, "You must have some processes to kill in killlist.txt\n"); system("pause"); return 1; } /* allocate memory for array */ pKillList = (char **)malloc(lines * sizeof(char *)); assert(pKillList != NULL); for (int i = 0; i < lines; i++) { pKillList[i] = (char *)malloc(1024 * sizeof(char)); assert(pKillList[i] != NULL); } /* put file contents in to kill list array */ fp = fopen("KillList.txt", "r"); if (fp == NULL) { perror("fopen (KillList.txt)"); system("pause"); return 1; } int currentLine = 0; while (!feof(fp)) { if (fgets(pKillList[currentLine], 1024, fp) != NULL) { /* remove new line character if it exists? */ if (pKillList[currentLine][strlen(pKillList[currentLine]) - 1] == '\n') { pKillList[currentLine][strlen(pKillList[currentLine]) - 1] = '\0'; } /* make process name uppercase for string comparisions later on (windows has no strcasecmp? :( ) */ for (int k = 0; k < strlen(pKillList[currentLine]); k++) { pKillList[currentLine][k] = toupper(pKillList[currentLine][k]); } // printf("%s\n", pKillList[currentLine]); currentLine++; } else { if (!feof(fp)) { printf("some error occured!?\n"); } } } fclose(fp); /* * run through each process */ /* get process list */ if (!EnumProcesses(p, sizeof(p), &count)) { perror("EnumProcesses"); fprintf(stderr, "Couldn't get process list\n"); system("pause"); return 1; } /* number of processes in list */ numP = count / sizeof(DWORD); /* for each process in the list */ for (int i = 0; i < numP; i++) { HMODULE hMod; DWORD cbneeded; char pName[1024]; /* get a handle to the process with terminate privs */ ph = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE, p[i]); /* get the name of the exe / file */ if (EnumProcessModules(ph, &hMod, sizeof(hMod), &cbneeded)) { GetModuleBaseName(ph, hMod, pName, 1024); /* if this exe / file is in the kill list, kill it */ for (int j = 0; j < lines; j++) { /* make process name uppercase for string comparision with process kill list */ for (int k = 0; k < strlen(pName); k++) { pName[k] = toupper(pName[k]); } if (strcmp(pName, pKillList[j]) == 0) { printf("Killing process %s\n", pKillList[j]); TerminateProcess(ph, 0); killed++; } } } //printf("%d. %s\n", i, pName); CloseHandle(ph); } printf("Killed %d processes\n", killed); system("pause"); } Share this post Link to post Share on other sites More sharing options...
OptikaliLLusion Posted December 31, 2005 Posted December 31, 2005 Thanks a lot man! Mind if I link to this on some other gaming sites I go to? EDIT: Link times out :S Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted December 31, 2005 Posted December 31, 2005 Thanks a lot man! Mind if I link to this on some other gaming sites I go to? EDIT: Link times out :S 608089[/snapback] Well, if you're going to do that I would rather you find somewhere to actually host the file. I only have ADSL, it'd kill me (the link is to a webserver sitting in my cupboard lol) As for it timing out, hm..... *looks in to issue* Thanks for pointing that out. Looks like noip has updated with an internal IP address for some reason. I'll sort that out..... Also updated the program a bit so it can use other files but defaults to KillList.txt. Either drag a text file over the .exe (should work), or should be a command line like.... EndTasks.exe "GamingKillList.txt" EDIT: Dont know why noip did that. Had to update it manually... try again! Share this post Link to post Share on other sites More sharing options...
OptikaliLLusion Posted December 31, 2005 Posted December 31, 2005 K, gonna upload it to RapidShare thanks! Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted January 6, 2006 Posted January 6, 2006 #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <psapi.h> #include <assert.h> #define MAX_P_SIZE 1024 #define DEBUG 0 /* * Structures :-) */ struct ListNode { ListNode *next; char pKill[MAX_P_SIZE]; } ListNode_t; struct LinkedList { ListNode *head; ListNode *tail; ListNode *cur; } LinkedList_t; /* * Function prototypes */ void AddToList(LinkedList *, char *); void ConvertToUpperCase(char *); void SetListCurToStart(LinkedList *); /* * Convert each character in a string to upper case */ void ConvertToUpperCase(char *str) { int strLen = strlen(str); for (int i = 0; i < strLen; i++) { str[i] = toupper(str[i]); } } /* * Add item to linked list */ void AddToList(LinkedList *list, char *data) { if (list->head == NULL) { #if DEBUG printf("Adding list head\n"); #endif list->head = (ListNode *)malloc(sizeof(ListNode)); assert(list->head != NULL); list->cur = list->head; list->tail = list->head; } else { #if DEBUG printf("Adding list item\n"); #endif list->cur->next = (ListNode *)malloc(sizeof(ListNode)); assert(list->cur->next != NULL); list->cur = list->cur->next; list->tail = list->cur; } strcpy(list->tail->pKill, data); list->tail->next = NULL; } /* * Run through list and free each node, starting from head. */ void FreeList(LinkedList *list) { ListNode *tmp; SetListCurToStart(list); while (list->cur != NULL) { #if DEBUG printf("Freeing list node with data content: %s\n", list->cur->pKill); #endif tmp = list->cur->next; free(list->cur); list->cur = tmp; } list->head = NULL; list->tail = NULL; list->cur = NULL; } void SetListCurToStart(LinkedList *list) { list->cur = list->head; } /* * Good old main */ int main(int argc, char **argv) { DWORD p[MAX_P_SIZE], count; int numP, lines = 0, killed = 0; HANDLE ph; FILE *fp; char fbuf[MAX_P_SIZE], *filename = "KillList.txt"; LinkedList lKillList; /* make all variables null */ memset(&lKillList, 0, sizeof(LinkedList)); /* if there's a filename passed in to use, use it instead of the default KillList.txt */ if (argc > 1) { filename = argv[1]; } printf("Using kill list: %s\n", filename); /* * get process kill list info */ /* open kill list file */ fp = fopen(filename, "r"); if (fp == NULL) { perror("fopen"); system("pause"); return 1; } /* put file contents in to linked list and count lines */ while (!feof(fp)) { if (fgets(fbuf, MAX_P_SIZE, fp) != NULL) { /* remove new line character from string if it's there */ if (fbuf[strlen(fbuf) - 1] == '\n') { fbuf[strlen(fbuf) - 1] = '\0'; } /* make text uppercase */ ConvertToUpperCase(fbuf); /* add to list */ AddToList(&lKillList, fbuf); lines++; } } fclose(fp); /* the file must have at least one process to kill in it */ if (lines < 1) { fprintf(stderr, "You must have some processes to kill in %s\n", filename); system("pause"); return 1; } /* * run through each process */ /* get process list */ if (!EnumProcesses(p, sizeof(p), &count)) { perror("EnumProcesses"); fprintf(stderr, "Couldn't get process list\n"); system("pause"); return 1; } /* number of processes in list */ numP = count / sizeof(DWORD); /* for each process in the list */ for (int i = 0; i < numP; i++) { HMODULE hMod; DWORD cbneeded; char pName[MAX_P_SIZE]; /* get a handle to the process with terminate privs */ ph = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE, p[i]); /* get the name of the exe / file */ if (EnumProcessModules(ph, &hMod, sizeof(hMod), &cbneeded)) { GetModuleBaseName(ph, hMod, pName, MAX_P_SIZE); /* make process name uppercase */ ConvertToUpperCase(pName); /* if this exe / file is in the kill list, kill it */ SetListCurToStart(&lKillList); while (lKillList.cur != NULL) { if (strcmp(pName, lKillList.cur->pKill) == 0) { printf("Killing process %s\n", lKillList.cur->pKill); TerminateProcess(ph, 0); killed++; } lKillList.cur = lKillList.cur->next; } } #if DEBUG printf("%d. %s\n", i, pName); #endif CloseHandle(ph); } FreeList(&lKillList); printf("Killed %d processes\n", killed); system("pause"); } Should be a slightly better way of doing it as you dont need to go through the file twice this way Also fixed a silly toupper() mistake, put it in the wrong bit of the loop is all... doesn't actually break anything, just wastes a bit of CPU time. You wont be able to notice the difference between this one and the old one to be honest, but I have put up the binary anyway. http://bone.servebeer.com/EndTasks2.zip Share this post Link to post Share on other sites More sharing options...
Recommended Posts