In case someone doesn't want to set up parental control (someone wants to lock the computer from themselves, not their kids), here is another solution using only Task Scheduler, which I'm currently using:
- Start menu --> Type "Task Scheduler" --> Open Task Scheduler.
- Create New Task
- Set these properties in the General tab:
- Name: choose a task name
- Check Run only when user is logged on
- In the Triggers tab:
- "New..."
- Beginning the task: On a schedule
- Settings: Daily
- Set the hour you want to turn off your computer
- Check Repeat task every: 5 minutes for a duration of 1 hours (or 8-9 hours, depending on you)
- Check Stop all running tasks at end of repetition duration
- Check Enabled
- OK
- In the Actions tab:
- "New..."
- Action: Start a program
- Program/script: powershell.exe
- Add argument: -command add-type -assemblyname System.Windows.Forms; [System.Windows.Forms.Application]::SetSuspendState([System.Windows.Forms.PowerState]::Suspend, $false, $false)
- In the Conditions tab:
- In the Settings tab:
This schedule will put your computer to sleep at the chosen time. If you try to turn the computer back on, it will continue to sleep every 5 minutes (in 1 or 9 hours - depending on your setup). This sleep action cannot be prevented. The computer went sleep, not turn off, so no worry about unsaved work.
Note: there is no warning display before the computer goes to sleep. You can create another Task Schedule to remind you of sleep time.