You can set triggers for tasks, as opposed to running on a schedule.
- Start Task Scheduler from the start Menu
- Select the Task Scheduler Library in the left nav pane
- Select Action > Create Task... (not Create Basic Task...) from the menu bar
- In the new Create Task window, select the Triggers tab
- Click on the New... button
- In the "Begin the task:" drop down, select "At log on" or "On workstation unlock"
- Repeat and create a second trigger for the task that covers the one you didn't select before
- configure the rest of the task normally