Killing a Windows process with Batch

I recently started with some DOS basics and batch scripting, therefore I have built this Batch script. In this blog I will tell you what it does, show you the code, and how to use it. So lets start.

What does the script do?

It actually doesnt do anything fancy other than killing/stopping a running process. Say there is a program that hanged itself up, like the Internet Explorer. Normally people hit the [Ctrl]+[Alt]+[Del] Keys to get to the taskmanager and kill the not responding process. Well this Batch program will ask the user to enter the process name like iexplore.exe and will kill/stop it. After that is done it will ask the user if he/she wants to kill another process. If you enter yes then it will start the program again, if he/she enters no, the program will end.

The Code

I know the Geeks reading the blog will want to see the code :D so here it is:


:: Disables displaying the command itself
@echo off
:: Puts a Title on the Batch Window
title Kill a Process
:: Makes the background black and the font color green
color 02
:: label
:start
:: Message to tell the user to enter a process (e.g. iTunes.exe)
set /p prozess=Which process do you want to kill?
:: Kills/stops the process provided by the user
taskkill /f /im %prozess%
:: asks the user if he/she wants to do the program again
set /p again=kill another process?
:: if the answer is yes then go back to the label named start and run the program again
if %again% == yes goto start
:: pauses the program and ends it when the user presses any key
pause

You can change the code however you want!

How to use the code to run the Program?

Instead of blah blahing you how to use it, I give you a step-by-step instruction:

  1. Copy the code and paste it into a text editor, such as notepad
  2. Save the program with a .bat extension (be sure the Filetype is set to All types (*.*))
  3. Run the file by either double-clicking on its icon or typing in its name in the Command prompt

Conclusion

I know this code isn’t perfect, i am just a beginner in Batch programming, but you can change the code to however you want. If you have any suggestions on how to change it or what you did, please leave a response to this blog.

Other than that, Happy Hacking! :D

Advertisement

~ by austrogeek on December 8, 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.