Script to close an application


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)

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.