Script to close an application

Posted on 2006-04-04
Last Modified: 2012-06-27

I often forget to close an application before I "retire" for the evening.  One of my backup routines won't backup files that are still open.

Can someone please provide a script that will close a specific application with two options:
1) Force it closed (even if it prompts to save unsaved changes)
2) Don't force it closed (if it prompts to save unsaved changes, leave it alone until morning)

Question by:SAbboushi
    LVL 82

    Accepted Solution

    You can do that with a simple taskkill command:
    taskkill /im application.exe /t /f
    will close the program (/im, "image") named application.exe including child processes (/t, "tree kill") and force (/f) it to close.
    taskkill /im application.exe
    will just send the terminate signal to application.exe, whether and how it closes is up to the application (so if the application supports to ask for unsaved changes when exiting, it will ask, otherwise it will terminate).
    LVL 3

    Assisted Solution


    Yes oBdA is right you can simply make a batch file to run taskkill but you CANNOT:

    1) Use this batch file on systems different from XP Professional (XP home, 2000 or prior don't have the taskkill command)

    2) Check wheter ANY application is asking for you to save or not because it's application dependent. Different applications use different saving policies there're programs like MS Word which will save a temporary copy after x minutes and then will ask you to save (in general many word processors act like this) or other applications like compilers or management or audio/video editing applications that will NOT save anything untill you specifically tell them to save. Moreover each application has its own way of implementation. Depending on the application it will save data in a file or a database (commit a transaction) or send data through network or print last's very very variable. :-)

    To just make a most portable version of the batch file oBdA suggested simply use the   pskill.exe   utility   downloadable from here:

    It works on many Win32 systems even non-XP and it works in a very similar way like taskkill. The functionality of the batch file and the way it should be made/used are just the same as oBdA told you...

    Marco Del Percio


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article ( first and run the tool TDSSKiller ( to get rid of the infection. Once done, and if the …
    We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now