command line version of the windows taskmgr
Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: command line version of the windows taskmgr

  1. #1

    command line version of the windows taskmgr

    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:

    Code:
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
    *                                                                                  *
    *  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 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, 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;
    }
    i hope you find it useful

    [edit]had to alter the above code to make it compatible with more systems (changed the "long code" to "unsigned long code").[/edit]

  2. #2
    King Tutorial-ankhamun
    Join Date
    Jul 2004
    Posts
    897
    On XP you can use the commands:

    tasklist
    taskkill

    Thanks for the code.

  3. #3
    Senior Member
    Join Date
    Feb 2002
    Posts
    130
    Nice job,

    there is also pslist and pskill from the sysinternals guys, you can manage and list remote processes too, very useful

    http://www.sysinternals.com/ntw2k/freeware/pslist.shtml
    http://www.sysinternals.com/ntw2k/freeware/pskill.shtml

    cheers

    uknetsec

  4. #4
    i know the tools, but mine combines the two, it first lists the processes, and then you have the option of killing one of them...

  5. #5
    Blast From the Past
    Join Date
    Jan 2003
    Posts
    729
    &lt;security thoughts&gt;
    you woulnt be able to use this against remote comps would you?
    i.e. from standard user mode on one comp shutdown the firewall on the other comp
    &lt;/security thoughts&gt;

    and no im not telling ppl to go hack with this...just wondering if it would be possiable
    work it harder, make it better, do it faster, makes us stronger

  6. #6
    Senior Member
    Join Date
    Feb 2002
    Posts
    130
    i know the tools, but mine combines the two, it first lists the processes, and then you have the option of killing one of them...
    So it does, I obviously didn't look at it closely enough the first time, nice piece of code, mking my head spin a bit at this time of night after looking at .net code for the past 3 hours

  7. #7
    Member gn0min0mic0n's Avatar
    Join Date
    Mar 2004
    Posts
    43
    hexadecimal: Irongeek mentioned tasklist/taskkill: both allow remote access...haven't tried this program yet, though i imagine it might be used in this way...anyone tested this yet (remote usage/administration)?

  8. #8
    you woulnt be able to use this against remote comps would you?
    i.e. from standard user mode on one comp shutdown the firewall on the other comp
    if you have a remote shell, then this is pretty easy to use, that's why i wrote it in the first place

  9. #9
    Senior Member Spyrus's Avatar
    Join Date
    Oct 2002
    Posts
    742
    What is a good program to compile the code with? i am by no means a programmer so i would like to compile to an exe or whatever so I can try it out.
    Duct tape.....A whole lot of Duct Tape
    Spyware/Adaware problem click
    here

  10. #10
    Senior Member
    Join Date
    Jul 2003
    Posts
    634
    try dev C++ by bloodshed or LCC, both are free.

    i2c

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides