Batch scripts to turn on & off Tasks in Task Scheduler


In a previous post (Microsoft Task Scheduler Tips & Tricks) I told you how to create a basic task in the Microsoft Task Scheduler to remind you to stand up once every 30 minutes.

While this is a great way to create a reminder – it can be time-consuming to go into Task Scheduler to turn your reminder on or off (e.g. you don’t want your reminder popping up while you’re giving a presentation or watching a movie).

Here’s a new tip on how to create two batch scripts to quickly turn your reminder on or off:

To turn your task off:
Open a notepad application (As a plug – I prefer Notepad++) and save the following script:


SCHTASKS /change /tn "Stand Up Reminder" /DISABLE
PAUSE

You will need to change the text in quotes (e.g. “Stand Up Reminder” above) to match whatever you named your script in Task Scheduler.

Next, save the script with a name like “Disable standup reminder.bat” (Note: you must save the file with the extension “.bat” instead of a “.txt” document). I suggest you save it to your desktop or pin it to your Start bar for easy access.

To turn your task back on – follow the same steps as above but use the following script instead:


SCHTASKS /change /tn "Stand Up Reminder" /ENABLE
PAUSE

As always, please let me know if you have any questions in the comments below!

Automating File/Folder Deletion


As promised in my last post, here is a sample batch file for automating deletion of files or folders.

For a tutorial on setting up a task in Windows Task Scheduler – please see the following previous post:

Assuming you have set up your temporary file structure as suggested in my last post, save the following code in a .BAT file and set up an automated task to run it as a program on a scheduled.


REM CD C:\TMP\
RMDIR /S /Q C:\TMP\

REM CD C:\TEMP\
RMDIR /S /Q C:\TEMP\

REM CD "C:\Users\USERNAME\AppData\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\"
RMDIR /S /Q "C:\Users\USERNAME\AppData\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\"

REM CD "C:\Users\USERNAME\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\"
RMDIR /S /Q "C:\Users\USERNAME\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\"

PAUSE

You will need to update the code with your username in the 4 places that say “USERNAME”.

This code will delete all files in the C:\TEMP & C:\TMP folders as well as cleanup after Macromedia’s Flash Player which I find tends to leave quite a few temporary folders and files behind.

When the code runs, it will pause at the end for you to review its progress until you press any button.

Happy New Years!

Microsoft Task Scheduler Tips & Tricks


I use Microsoft Task Scheduler for a couple of different jobs and over time I’ve found that different jobs require different “tricks” to get them to work properly. I’m going to try to summarize some of those tips & tricks here for you.

First though, I’m going to quickly sketch out how to create a simple task in Task Scheduler. If you are already comfortable with creating tasks feel free to skip to the Tips & Tricks section below.

As an example task – I will walk you through creating a scheduled pop-up reminder in Task Scheduler.

  1. In Windows 7 or Windows 8, press the Windows key to bring up your start menu/page and type “Task Scheduler”
  2. Open the program with that name
  3. On the right hand side of the window, click the “Create Task” button in the “Actions” list
  4. Type a name for your task in the “Name” field
  5. In the “Configure for:” drop down menu at the bottom of the screen, choose the operating system that you are using (for some reason on Windows 7, this menu defaults to Vista.)
  6. Select the “Triggers” tab along the top of the window
  7. Click the “New…” button
  8. Select from the various options what type of schedule you would like your task to run on. For this example, I have chosen to begin the task on a schedule, Daily, Repeat task every 30 minutes for a duration of “Indefinitely”
  9. Click the “OK” button
  10. Select the “Actions” tab along the top of the window
  11. Click the “New” button
  12. From the “Action” pull down menu, I have selected “Display a message”
  13. Title: Reminder!
  14. Message: Stand up & stretch!
  15. Click the “OK” button
  16. Select the “Conditions” tab along the top of the window
  17. Depending on the task, I usually deselect the “Stop if the computer switches to battery power” and “Start the task only if the computer is on AC power” options.
  18. Select the “Settings” tab along the top of the window
  19. Select the “Run task as soon as possible after a scheduled start is missed”
  20. Change the “Stop the task if it runs longer than:” option to 1 hour. This will keep a task from running in the background chewing up processing power if it fails to exit cleanly
  21. Click “OK”
    1. You now have a basic reminder set to go off every 30 minutes to help you keep your blood flowing while you read my long tutorials 😉

      Tips & Tricks

      Okay, now for some more detailed Tips & Tricks.

      1. On system start-up – if your task calls a batch job, and keeps failing to execute, you may need to grant your user(s) the “Logon as a batch job” permission
        1. To do so: In the Control Panel, open Administrative Tools, then Local Security Policy (Or simply type “Local Security Policy” in your start menu)
        2. Beneath Security Settings, open Local Policies and highlight User Rights Assignment
        3. Locate Log on as a batch job. Open the properties and add any users that need this permission
        4. When finished, save your changes and close the Local Security Settings window
        5. Your changes should take effect immediately. To make changes to the Domain Security Policy, on a domain controller, use the Domain Security Policy utility in the Control Panel
      2. Instead of choosing to start a task when the system starts, choose “At logon” with the check-box for “Any user” checked. Sometimes a program will behave better if you start it at log on instead of at system start-up.
      3. If you have a lot of programs that start at system start-up or user log on, you may want to stagger your tasks to start over 30 seconds or a minute after logon to try to give the computer a break between tasks. This can help keep your computer from freezing up, trying to start so many programs at once.
      4. Try experimenting with calling batch files on a scheduled basis. You can automate many different chores this way. Examples that I run including automating file backups, automating e-mail backups, reminders to stand & stretch, automatically start programs at logon, deleting temporary file directories on a regular basis, etc.