Question Locked

.Bat file to kill processes upon confirmation

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi all,

I'd would like some help creating a simple (yeah i know n00b here) .Bat file that kills processes [b]but[/b] 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

6 replies

by seanferd

you will either have to copy Choice from an older system (or an old dos tools dir on the OS installation media, if available), or you would use set /p.

Type choice /? or set /? at the prompt for command help & info.

You will probably be using something like IF %variable%==Y goto (section that executes taskill).

by rob miners

If you want to just be able to run the command with no user interaction use this switch.

echo y| taskkill /im iPodService.exe /f

:: I modified this file to open Notepad.exe as an example.
:: Cut Below and rename the file to menu.bat
============================================================

@ECHO OFF
CLS
:LOOP
:: ECHO A. Menu item A
ECHO A. NOTEPAD
ECHO B. Menu item B
ECHO C. Menu item C
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO NOTEPAD
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:NOTEPAD
:: ECHO Insert commands for Item A.
C:\WINDOWS\NOTEPAD.EXE
GOTO Again
:ItemB
ECHO Insert commands for Item B.
GOTO Again
:ItemC
ECHO Insert commands for Item C.
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End
=============================

Keep us informed as to your progress if you require further assistance. :D

Edit: to add a space

by rob miners

Keep us informed as to your progress if you require further assistance.


If you think that any of the posts that have been made by all TR Members, have solved or contributed to solving the problem, please Mark them as Helpful so that others may benefit from the outcome. ;) :D

This discussion is closed to new replies.