28

Is there a way to automagically determine if a program is running and close it at scheduled time, say 3 am every day?
Maybe use task scheduler to close said application? if this is possible any direction would be appreciated.

Vista or Win7

5 Answers 5

38

Many ways to go about doing this. A simple solution would be to simply use Task Scheduler to run a batch script like this at 3 am every day:

taskkill /f /im programname.exe

save as something like closeprograms.bat and substitute programname.exe with the name of the executable you wish to kill. Set Task Scheduler up to run this batch file whenever you want.

  • /f means that it is forcefully terminated
  • /im precedes the "image name" = process name
4
  • 2
    Is there a way to do it without /f? I want the program to be able to handle its stuff when closing instead of killing it.
    – Bowi
    Commented Jun 26, 2018 at 15:40
  • 1
    No need to put this in a batch file. Just set "Program/script" to: taskkill, and set "Add arguments" to: /f /im programname.exe
    – Alan L
    Commented Nov 12, 2018 at 3:59
  • 1
    @Bowi You can do it without /f but it might not actually close, if the program asks you to save files, etc. But you could do it nicely first and then force it afterward
    – endolith
    Commented Aug 6, 2019 at 15:34
  • 1
    Solution is still valid for Windows 10
    – supersuf
    Commented May 8, 2020 at 8:47
4

In Windows 10, a note about the AT command:

The AT command has been deprecated. Please use schtasks.exe instead.

A complete schtasks example (type this at a windows command prompt):

SCHTASKS /Create /SC DAILY /ST 03:00:00 /TN sometaskname /TR "taskkill /f /im TheProgramYouWantToStop.exe"

To kill a program once at a specified time (rather than daily):

SCHTASKS /Create /SC ONCE /ST 03:00:00 /TN sometaskname /TR "taskkill /f /im TheProgramYouWantToStop.exe"

You can check on the task with

SCHTASKS /Query /TN sometaskname

Note: The task will also appear in Computer Management->Task Scheduler->Task Scheduler Library with the name sometaskname and you can edit or delete it there. Sometimes you'll need to press F5 to refresh the task list in computer management to be able to see the task.

2

To schedule a program from the Windows command line use this command:

AT hours:minutes /every:date command

So if you want to schedule something for 3:00 AM every day.

AT 03:00 /evry:M,T,W,Th,F,S,Su "command"

For more help check AT /?, CMD /? and this page.

TASKLIST lists the applications that are running (type TASKLIST /? for help), but I don't know of a way to combine these two commands to get the result you want or if there is other way to do it; check the site above and google for batch files and VBScript.

1

System Scheduler seems to match your needs. From the website:

System Scheduler is an excellent tool to schedule unattended running of applications, batch files, scripts and much more.

For anyone used to using MS Windows own Task Scheduler, or the older AT or WinAT commands, System Scheduler is an ideal and easy to use replacement, with more flexibility and features. System Scheduler runs totally independently of the MS Windows Task Scheduler and has no dependencies on it.

Also, you can schedule popup reminders so you'll never forget those important appointments and things to do. Reminders, tasks and other events can be set to run once or every minute, hour, day, week, month or year and several variations on these. Popup Reminders can be snoozed as required.

System Scheduler not only allows you to launch programs at scheduled times but also to send keypresses and mouseclicks to those programs. This allows you to not only schedule programs to run overnight or at the weekend but also get those programs to do useful things while unattended. A really powerful feature.

Finally, the Free vesion of System Scheduler also includes a Window Watcher feature. The program will check for the existence of a particular window and send keypresses or send the window a close signal to terminate running applications. Useful for triggering actions or handling error messages while you are away.

1

AT 07:21AM /every:M,T,W,Th,F,S,Su taskkill /f /im PROGRAM.EXE

You can get the program name by going into task manager and clicking the "Processes" tab.

You must log in to answer this question.