Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: .bat file to end a process...  (Read 7510 times)

0 Members and 1 Guest are viewing this topic.

PHREKER

  • Guest
.bat file to end a process...
« on: November 24, 2007, 05:33:25 PM »
Can someone please help me? I'm trying to find a command line that will end a process like when you open task manager and go to the process tab and end processes. The reasoning is when I run my virus removal software it tells me to end a few things and it would just be easier to click a .bat file then to bring up task-manager ..please help ;D

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: .bat file to end a process...
« Reply #1 on: November 24, 2007, 06:27:30 PM »
A similar question appeared earlier this week. I guess some code just never dies.

Code: [Select]
@echo off
:loop
for /f "tokens=1 skip=3" %%f in ('tasklist') do (
        if /i .%%f equ .%1 taskkill /im %1 /f
        )
if not .%2==. (
        shift
        goto loop
        )

Save the above snippet with a bat extension. You can then run your batch file to kill any number of jobs named on the command line.

ie: If you saved the file as RunTheKill, you could run it as:

RunTheKill excel.exe iexplore.exe

Both Excel and Internet Explorer will be killed.

Good luck.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

PHREKER

  • Guest
Re: .bat file to end a process...
« Reply #2 on: November 24, 2007, 07:15:29 PM »
it says tasklist  is not recognized as .... am i supposed to put the tasks in there?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: .bat file to end a process...
« Reply #3 on: November 25, 2007, 06:21:44 AM »
Apparently my crystal ball was not plugged in. Tasklist and Taskkill are utilities installed with some NT operating systems. (Note: XP Home has TLIST).

You can download both from here

Happy coding.  8)

Next time please mention your OS. You'd be surprised how helpful that little piece of information can be.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

silvrwood



    Rookie

    Re: .bat file to end a process...
    « Reply #4 on: October 13, 2008, 10:26:28 AM »
    What would the code be for Windows Server 2003?

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: .bat file to end a process...
    « Reply #5 on: October 13, 2008, 04:14:17 PM »
    It's flattering you would drag up an old post from 11 months ago. Gives new meaning to Groundhog Day. ;D

    Windows XP pre-dates Windows Server 2003. Seems reasonable taskkill and tasklist would be included with the newer OS. The snippet has been slightly modified from the original.

    Code: [Select]
    @echo off
    :loop
    for /f "tokens=1-2" %%f in ('tasklist') do (
    if /i %%f equ %1.exe taskkill /F /IM %%f 2>nul
    )
    if .%2==. goto :eof
    shift
    goto loop


     8)

    « Last Edit: October 13, 2008, 04:58:34 PM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    silvrwood



      Rookie

      Re: .bat file to end a process...
      « Reply #6 on: October 17, 2008, 01:51:41 PM »
      Thanks so much!   ;D