lepricaun Posted September 12, 2004 Report Share Posted September 12, 2004 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:/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** File: prokill.c ** ** Purpose: commandline processkiller / taskmanager for windows ** * * Usage: compile to prokill.exe and run it! ** ** Copyright (C) 2004 Scorpius, [email protected], 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 pid,exitcode,term; unsigned 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, [email protected], 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;} i hope you find it useful :)(i've attached the program and source).[edit]altered the code so that is compatible with (almost) all systems. (changed the "long code" to "unsigned long code")[/edit]prokill.zip Quote Link to comment Share on other sites More sharing options...
Scarecrow Man Posted September 13, 2004 Report Share Posted September 13, 2004 Very nice. I tested it and it seems to work just fine. Why would you want this though? Quote Link to comment Share on other sites More sharing options...
lepricaun Posted September 13, 2004 Author Report Share Posted September 13, 2004 Very nice. I tested it and it seems to work just fine. Why would you want this though?because there are tools like pskill and pslist, but if you wanted to kill a program:run pslist --> get PID.run pskill PID.with my program it's just:run prokill --> view and enter PID..and why i wanted it for the commandline:if you have it on a remote machine and you have a shell on that machine (presuming it is your own machine). then it would be pretty easy to administer the processes ran on that machine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.