Script to close an application

Hi-

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)

Thanks-
SAbboushiAsked:
Who is Participating?
 
oBdACommented:
You can do that with a simple taskkill command:
1)
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.
2)
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).
0
 
marco_delpercioCommented:
Hi

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.