CyberNotes
Tutorial Thursday


A couple of weeks we wrote up a tutorial on how to create a single batch file that would simultaneously launch several different applications. It’s a handy little trick that many people found useful because they are frequently running the same programs on their computer. For example, when you start your computer you might open a browser, media player, and document editor. Instead of clicking on each of those shortcuts individually you can create a single batch file that will do the dirty work.

In the comments of that article “ExitRitual” asked a great question. He was wondering if it would be possible to do the same thing, but for closing programs. This would come in handy if, for example, you were getting ready to play a computer game. Most people shutdown a majority of the running applications to ensure that the game runs smoothly, and it can all be done in a single batch file.

We’ve shown how to do something similar in the past, but we were using a free third-party program because it was a little more powerful for the task at hand. This time around we’re going to use a command line option that is built-in to Windows.

–Instructions–

  1. Open Notepad (Start Menu -> Accessories -> Notepad):
    Notepad
  2. Now you need to find the filename of the programs you want to close. I believe the best way to do this is to open up the Task Manager. Do this by right-clicking on the Taskbar and choosing the Task Manager option. Then look for the filename of the program you want to close.
    Task Manager Image Name
  3. Now you’ll need to use the taskkill command in Notepad, along with the filename(s) that you just grabbed in the previous step. Each command will look like this:

    taskkill /im firefox.exe

    Where firefox.exe is the filename of the program you want to close. Put each of these commands on a separate line like this:
    Batch Close

  4. Save it as a .BAT file by manually entering in the extension at the end of the file name.
    Save Batch File
  5. Double-click on the new file that you just created to test out the results. Each program listed will be closed in a friendly fashion instead of being shutdown forcefully.

The batch file will be smart enough to skip over any applications that are currently not running. So throw all of those extra programs in the batch file, and don’t forget to include things that might be running the the System Tray.

There Are 28 Comments

  1. After that article where i asked about closing applications,i went on a bit of a hunt, and found pretty much the above, but i also found that adding ” /f” to the end of each line can also forcibly close an application. Not essential, but quite handy.

    One odd side-effect i’ve found in using a batch file to launch applications (specifically those that sit in the system tray) is that it resets the hide/show options for the icon, not a major annoyance, but mildly confusing none-the-less…

    Using a batch file to close applications really does help quite a lot, as you say, when preparing to play games, it can really give you that little bit extra back to use. Very handy indeed ^_^

    …Now i just need to figure out how to add a theme change to that batch file (to swap between full-on Aero, and windows classic, thus saving a lot of ram).. one step at a time, i suppose..

    Anyway, thanks for posting the original article, until then i had NO idea such a thing was possible, and it’s saved me a notible amount of time and hassle :)

  2. It’s odd, but it works erratically on my PC. And I can’t put my finger on it why… somtimes it does work, sometimes it doesn’t, then I thought it had to do with capitals in the program names but then again it does close ADC.exe but it doesn’t close Wakoopa.exe… I’ll fiddle with it some more. Would be just *great* if this wanted to work properly :D

  3. First of all, forgive me for living up to Linux hippie cliché.

    In Linux, we’d just do this in a terminal:
    killall calc && killall firefox && killall googletalk

    One command and you’re all done. You’re just a few more click away from making it a script that you can use over and over. :)

  4. Is there any way It could shutdown a list of processes after a certain period of windows inactivity?

  5. SlowMotion,

    You would need to develop a program that detects for Windows activity. This can be done using the Win32API, using SystemParameters.

    Then you could call on this batch file once the conditions have been met.

  6. Pieter wrote:
    In Linux…

    The “&&” seems to work in windows too… (As much as I loathe to give MS an inch.)

  7. Just for you to know,
    It doesn’t close firefox 3 beta 2 on XP. :?
    And if there need to save documents, it’s doesn’t pop the box that ask for (excel 2000).

    Please let me know how to do it.

  8. ExitRitual wrote:
    Anyway, thanks for posting the original article, until then i had NO idea such a thing was possible, and it’s saved me a notible amount of time and hassle :)

    That’s what we love to hear! There’s nothing like knowing that we’ve saved people some time.

    satur9 wrote:
    It’s odd, but it works erratically on my PC. And I can’t put my finger on it why… somtimes it does work, sometimes it doesn’t, then I thought it had to do with capitals in the program names but then again it does close ADC.exe but it doesn’t close Wakoopa.exe… I’ll fiddle with it some more. Would be just *great* if this wanted to work properly :D

    You can try using the /f switch on the line where you specify the program’s filename. As ExitRitual pointed out that will force a program to close, but you might want to be careful with how you use that. If you’re not careful you could end up losing a document or something if it hasn’t been saved.

    SlowMotion wrote:
    Is there any way It could shutdown a list of processes after a certain period of windows inactivity?

    It would be rather easy to make an application that did that, but I don’t think it can be done in a batch file.

    yvananda wrote:
    Just for you to know,
    It doesn’t close firefox 3 beta 2 on XP. :? And if there need to save documents, it’s doesn’t pop the box that ask for (excel 2000).

    Please let me know how to do it.

    I have no troubles closing the latest Firefox 3 nightly builds, so maybe for some reason there is a bug with it.

  9. Does this not work on Win2K? In the command window I get the message:

    “taskkill” is not recognized as an internal or external command, operable program or batch file.

    for every line that I’ve put into the batch file.

    :(

  10. Much easier: Click the programs in the taskbar > right-click and Close Group

    [unlockforus.blogspot.com]

  11. Dexter wrote:
    Does this not work on Win2K? In the command window I get the message:

    “taskkill” is not recognized as an internal or external command, operable program or batch file.

    for every line that I’ve put into the batch file.

    I think Windows 2000 users need to use the “kill” command, which works similarly.

    Mharr wrote:
    Much easier: Click the programs in the taskbar > right-click and Close Group

    [unlockforus.blogspot.co]…..-time.html

    That’s true, but it doesn’t work for apps running in the System Tray.

  12. Hello, from the moment I use Vista 32bits I lost “SmartClose” :( and I found this batch file so helpfull for me, but I have some problems with the programs in the system tray, many programs in there, before to close require a confirmation. :/
    I used /f without good result
    Any one here have any tip to close these programs using another command in the batch file?
    Thanks for your help (specially Ryan for this tool). :)
    God bless you, bye.

  13. The /f will only work if the program isn’t responding. You might be able to use something like this in the batch file:
    [cybernetnews.com]

  14. Hi All,
    We use taskkill to stop any process, what is the command to start any process.
    Thanks
    Sanjay

  15. With respect to programatically shutting down aero.. I believe:

    net stop “…”

    where … is the name of the Aero service (“Display” something or other) will do it.

  16. It took me a while to find this via Google but I’m glad I did. One question though: Is there any downside to killing a ‘process’ as opposed to ‘çlosing’ a program? Obviously unsaved data will be lost but apart from that, is any ‘damage’ done? I will primarily be using this to automatically close Thunderbird & Firefox before backup.
    Thanks for your time,
    Paul

  17. Unfortunately taskkill or kill do not work for me with windows 2000.
    I have tried /f as well. And many variations of the above sugesstions. Any more clues for me?
    thanks, Dantravels.

  18. Dantravels:

    kill firefox.exe

    worked in windows 2000 for me. Hope that helps.

  19. This did not work for me. I am running windows xp home edition service pack 3.

  20. Thanks a lot This works great saves me a lot of hassle
    Now I would love one that would switch from aero to classic if its possible someone mentioned something above anyone know how ?

  21. Thanks for that great “appkiller”.
    I got a question there, is it possible to shutdown, after closing this apps, with the same file?

  22. melovespot wrote:
    Thanks for that great “appkiller”.
    I got a question there, is it possible to shutdown, after closing this apps, with the same file?

    Yes, it is possible. You can use this command on one of the lines:

    SHUTDOWN -s -t 01

  23. is there a way to close all processes except a few essential ones for windows?something that ll take out the random process that i have overlooked to put in into the batch file?as in leave the system on with only clean legitimate processes i trust?

  24. curious…I wondered the same thing. I checked taskkill /? and experimented a bit on an XP SP 3 machine, and came up with the following command.

    “TASKKILL /FI “USERNAME ne SYSTEM” /FI “USERNAME ne LOCAL SERVICE” /FI “USERNAME ne NETWORK SERVICE” /FI “IMAGENAME ne msseces.exe” /FI “IMAGENAME ne explorer.exe” /FI “IMAGENAME ne taskmgr.exe” /IM * /T /F >> killall.log 2>&1″

    It will forcefully kill all processes and their children, except those list below, and append the output and any errors to killall.log in the working directory.

    Excludes

    1. all processes running under the SYSTEM, LOCAL SERVICE, and NETWORK SERVICE accounts
    2. explorer.exe (this means it doesn’t kill any open “Windows Explorer” windows either)
    3. taskmgr.exe
    4. msseces.exe (Microsoft Security Essentials)

  25. Sorry for the duplicate posts. There was an error and I didn’t think it was posting.

    Testing on Windows 7 revealed that the command will need to be ran as Administrator in Vista and 7. Consequently, if ran from a batch file, the log file will be created in c:\windows\system32 instead of the directory the batch file is executed from unless you edit the command to write to a absolute path.

    [vistax64.com]

  26. This article was VERY helpful. I made a few changes, but it would have been impossible without this article as a starting point.

    But, if I may add something. If you are running multiple instances of the same program, this kind of shits on you (as in two separate example.exe). I don’t know if it’s changes in 7 or what, but I had to tweak it a bit. I used:

    taskkill /f /t /im TASKNAME

    If I removed /f or /t it didn’t work right. Sometimes it would only close one instance, sometime none of them. I put /f /t in front of every line and it works like a dream.

  27. Thank you for the solution.
    This will be of great help to developers who wish to kill several backend programs at a time!

Leave Your Comment


Message is the only required field.
Emails are not published.