We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Script to close an application

SAbboushi asked
Medium Priority
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)

Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018
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).

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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 data...it'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: http://www.sysinternals.com/Utilities/PsKill.html

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

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.