Unfortunately, there are a number of assumptions you are making in your question that just won't work. I'll cover each of those below. While this information is covered in other questions and answers here on Super User, it can be difficult to "put together" all of the information. So while one might consider this a "duplicate" of those questions (as I originally did), it probably does need its own answer to aggregate all of the other related answers.
So, let's tackle this piece-by-piece:
You are trying to get cron
to work under WSL
The problem here is that WSL isn't designed to "start up" services at boot, since there is no concept of a WSL "boot". Please see this question for more information on that aspect.
You are trying to shutdown WSL via a Linux shutdown
command
WSL is a virtualized environment without direct control over the hardware. The Linux /usr/sbin/shutdown
command in WSL does not have access to the host hardware. The proper way to shutdown WSL itself is by running wsl --shutdown
(from PowerShell, CMD, or the Start Menu). This is covered in this question, although since it predates the wsl
, you have to look at the second answer.
You are trying to shutdown Windows via a Linux shutdown
command
As mentioned in the comments, the WSL lifecycle is different from that of Windows. WSL is software that runs in Windows. Shutting down the WSL environment is (to some extent) like exiting Notepad with File->Exit or Alt+F4. You wouldn't expect Windows to shutdown when you shutdown Notepad, nor should you expect Windows to shutdown when you shutdown WSL.
To shutdown Windows, see the shutdown.exe
command, covered in numerous other Super User questions.
Your real question is at the bottom -- How to do this with Task Scheduler. This question covers using shutdown.exe
in Task Scheduler, for starters. That can, at least, run the shutdown at 22:00.
Then it sounds like you also want to have something that checks if a user is trying to log in between the "quiet hours" and prevent it. That's covered in this answer with the Windows net user /time
command. Also see the other answers here for more along the lines of what you are trying to do.
Finally, you want to shut down Windows if it has been started up during the quiet times. This should also be done via a shutdown.exe
in a Task Scheduler task that repeats every so often. Tasks like this are covered in multiple answers here on Super User, but here's one for reference.
wsl.exe --shutdown
instead. If you want help troubleshooting the command that doesn't work you have to provide us more information. You can do that by performing an edit and giving us just a tad bit more information.