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
.Bat file to kill processes upon confirmation
Moderator: DosItHelp
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
-
- Posts: 3
- Joined: 24 Feb 2009 11:26
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!
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!
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
Steve,
This:
Means: Prompts the User for a Y or N to make sure before killing the task.
This:
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.
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.