hi all,
a couple of months ago i was searching really hard for a command line version of the windows taskmgr, but i wasn't able to find one
so today i decided to write one myself, my brain was extremely overheating during the coding :lol:, but i have finished it just a few minutes ago
since no one could give me a link or name from a similar program, i thought that it might come in handy for some people, so i decided to publish it under the GPL, so here is the source:
i hope you find it usefulCode:/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * File: prokill.c * * * * Purpose: commandline processkiller / taskmanager for windows * * * * Usage: compile to prokill.exe and run it! * * * * Copyright (C) 2004 Scorpius, scorpius_unknown@yahoo.com, all rights reserved * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h> #include <windows.h> #include <tlhelp32.h> int main(void) { int info,pid,exitcode,term; long code; HANDLE Snap,Process; PROCESSENTRY32 proc32; Snap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);/*take a snap of all processes*/ if(Snap==INVALID_HANDLE_VALUE) { printf("Error creating snapshot of current processes"); return EXIT_FAILURE; } proc32.dwSize=sizeof(PROCESSENTRY32); /*set size of structure*/ system("cls"); printf("Prokill.exe by Scorpius, scorpius_unknown@yahoo.com, 2004.\n\n"); printf("PID:\t\tPROCESS NAME:\n"); while((Process32Next(Snap,&proc32))==TRUE)/*while we haven't reached the final process*/ { printf("\n%d\t\t%s",proc32.th32ProcessID,proc32.szExeFile);/*print pid and processname*/ } CloseHandle(Snap);/*cleaning up*/ printf("\n\nEnter PID of process to kill (or 0 to quit): "); scanf("%d",&pid);/*get the PID of the process to kill*/ if(pid<1) { printf("Illegal PID."); return EXIT_FAILURE; } Process=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pid);/*obtain a handle to the process*/ if(Process==NULL) { printf("Illegal PID."); CloseHandle(Process); return EXIT_FAILURE; } exitcode=GetExitCodeProcess(Process,&code);/*get the exitcode from the process*/ if(exitcode==0) { printf("Unable to retrieve exitcode."); CloseHandle(Process); return EXIT_FAILURE; } Process=OpenProcess(PROCESS_TERMINATE,FALSE,pid);/*see if we have terminate rights*/ if(Process==NULL) { printf("Unable to terminate process."); CloseHandle(Process); return EXIT_FAILURE; } term=TerminateProcess(Process,code);/*terminate the process*/ if (term==0) { printf("Terminating process %d failed.",pid); CloseHandle(Process); return EXIT_FAILURE; } printf("Process %d killed successfully.",pid);/*all went fine, process is killed*/ CloseHandle(Process); return EXIT_SUCCESS; }![]()



LinkBack URL
About LinkBacks




