.Bat file to kill processes upon confirmation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stevetilsed
Posts: 3
Joined: 24 Feb 2009 11:26

.Bat file to kill processes upon confirmation

#1 Post by stevetilsed » 24 Feb 2009 11:33

Hi all,

I'd would like some help creating a simple (yeah i know n00b here) .Bat file that kills processes but requires me to confirm i wish for this to be done.

The background:
We have several programs at work that are memory hungry when left open for some time (i have the program left open for months at a time) The program takes a while to load and validate so i tend never to close and restart. Basically i would like to create a .Bat file that kills the process when i enter the letter 'Y' and press enter. This way i would be able to add this to scheduled tasks for my breaks and if i am going on my break on time i could say yes and leave it to do the rest.

I have managed to manually kill a process on a home PC my example follows

taskkill /im iPodService.exe /f

However i do not understand the choice command.

Is this even possible?
Any help or guidance is much appreciated!

Steve

_m
Posts: 6
Joined: 27 Jan 2009 10:56

#2 Post by _m » 24 Feb 2009 12:19

Code: Select all

@ECHO OFF
:START
CLS
TASKLIST
ECHO.
ECHO.1. Refresh
ECHO.2. End Process
ECHO.
ECHO.0. Exit
ECHO.
SET /P "OPTION=> "
IF [%OPTION%] EQU [2] (GOTO:END)
IF [%OPTION%] EQU [1] (GOTO:START)
IF [%OPTION%] EQU [0] (EXIT)
GOTO:START
:END
ECHO.
SET /P "PROCESS=Process Name: "
IF NOT DEFINED PROCESS (GOTO:START)
ECHO.
SET /P "YN=Are you sure? (Y/N): "
IF /I [%YN%] EQU [N] (GOTO:START)
ECHO.
TASKKILL /F /IM "%PROCESS%"
ECHO.
PAUSE
GOTO:START

stevetilsed
Posts: 3
Joined: 24 Feb 2009 11:26

#3 Post by stevetilsed » 24 Feb 2009 15:38

HI m,

thanks for the swift reply, i have copied it out and tested but cannot get it to work but possibly because i do not understand the IF statement below. below.

IF /I [%YN%] EQU [N] (GOTO:START)
ECHO.
TASKKILL /F /IM "%PROCESS%"
ECHO.
PAUSE
GOTO:START

I also guessing that the following line is where i enter my process name for example testing.exe (do i need the .exe?)

SET /P "PROCESS=Process Name: "

Thanks again!

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#4 Post by RElliott63 » 24 Feb 2009 15:57

Steve,

This:

Code: Select all

SET /P "YN=Are you sure? (Y/N): "
IF /I [%YN%] EQU [N] (GOTO:START)

Means: Prompts the User for a Y or N to make sure before killing the task.

This:

Code: Select all

TASKKILL /F /IM "%PROCESS%" 

Means: If the user does NOT type "N" above, then process the TASKKILL job with the Process Name "%PROCESS%". When it's finished killing the task, it pauses then goes back to the START tag.

stevetilsed
Posts: 3
Joined: 24 Feb 2009 11:26

#5 Post by stevetilsed » 25 Feb 2009 12:56

Cheers guys that worked wonders!

Post Reply