0

I am looking for a batch file to kill all programs listed on a text file this would be very useful

also i am looking for a batch file to link an exe or bat to a keyboard shortcut

Example would be when you click ctrl 5 to launch ie but the bat must link it to the keys

Justin

kriegy
  • 195
  • 1
  • 3
  • 14

1 Answers1

2

TEXTFILE.TXT

notepad.exe
iexplore.exe
chrome.exe

KILLIST.BAT

@echo off
for /f "tokens=*" %%x in (textfile.txt) do taskkill /IM %%x

Keep in mind that if there are multiple instances of the same program open that without more information than the name of the executable that taskkill.exe will simply kill the first instance it encounters, probably the first one opened.

A more exact method is to use the window name (even just a portion of it), use tasklist.exe to search for that, grab the PID (Process ID), then use taskill.exe /PID #### to kill that exact process.

Another choice would be to kill ALL the programs with the same file-name. Doing that could also be done by collecting PID's but is simpler to just 'count' them and kill them that way. (It's not really counting, but it's close.)

TEXTFILE.TXT

notepad.exe
iexplore.exe
chrome.exe

KILLIST.BAT

@echo off
for /f "tokens=*" %%x in (textfile.txt) do (
  for /f "skip=3" %%y in ('tasklist /FI "IMAGENAME eq %%x"') do (
    taskkill /IM %%y
  )
)

==================================================================================

EDIT: 2012/09/07

To create a keyboard short-cut for the batch file, you need to:

1) Open Windows Explorer and browse to where you have the batch file located.
2) Right Click -> KILLIST.BAT -> Create shortcut
3) Right Click -> KILLIST.BAT - Shortcut -> Rename
4) Delete - Shortcut -> Press [ENTER]
5) Right Click -> the new KILLIST.BAT -> Properties
6) Select -> the Shortcut tab
7) Click -> the box next to Shortcut Key:
8) Press -> the keys you want to make the shortcut from. (It will display them)
9) Click -> OK

You can do this with any shorcut, not just ones for a batch file.

For this method to work, you must keep the shortcut on the Desktop or in your Start Menu somewhere.

A better choice would be a Macro Generator like AutoHotkey.

James K
  • 4,005
  • 4
  • 20
  • 28
  • Thank you very much it worked like a charm and you explained it well what about the keyboard shotcut? – kriegy Sep 07 '12 at 10:50
  • I've added an explanation of how to create a keyboard shortcut, but it dates back to Windows 95 days (possibly even Windows 3.1, I don't recall) and is not reliable. Download a macro generator instead, many of them can do more than just play back keystrokes and mouse clicks. – James K Sep 07 '12 at 18:13
  • Actually, it is reliable, it just needs to be on the desktop or start menu. – James K Sep 08 '12 at 02:46