A More Controlled Windows OS Shutdown With Schedules!

Ryan HarrisRyan Harris
6 min read

Want to tell your computer when to shutdown but have steps in place to stop the shutdown in case you’ve changed your mind? Well I’ve got a solution for you, with thanks to Google’s Gemini and some Sources linked below in the credits you can tell your computer when to prompt you to go to sleep. If you press yes it’ll have a fail-safe just in case you didn’t actually mean to say yes to it shutting down in 2 minutes, the fail-safe will cancel the shutdown allowing you to continue working until your ready to log off!

Here’s the VBS Script I got Gemini to write for me, Thank you Google <3

It could probably be written better but I am no good with anything to do with VBS, I might try to learn it one day but for the moment since this works I’m just going to stick with the “If it ain’t broke, don’t fix it” motto.

Dim response, objShell, strShutdown, strAbort

response = MsgBox("Hi There, Time To Get Off For The Night Don't You Think?", vbYesNo + vbSystemModal, "Time To Sleep")

If response = vbYes Then
    ' Execute shutdown command
    strShutdown = "shutdown.exe -s -t 120 -f"
    set objShell = CreateObject("WScript.Shell")
    objShell.Run strShutdown, 0, false

    WScript.Sleep 100

    intShutdown = MsgBox("Computer Will Shutdown In 2 Minutes. Would You Like To Cancel The Shutdown?", vbYesNo + vbExclamation + vbApplicationModal, "Cancel Shutdown")

    If intShutdown = vbYes Then
        strAbort = "shutdown.exe -a"
        objShell.Run strAbort, 0, false
    End If
End If

You can take this code (copy and paste it) into a notepad, edit it to your liking and then save it as FileName.vbs or download the file by clicking here! and then doing CTRL + S or Right Clicking and pressing “Save Page As…” in your browser and save the file to where-ever you want!

However ensure that before you save it, change the “Save as type:” to be All Files else Windows will append a .txt onto the VBS file and it will not run.

What this will do is show a box on your screen saying “Hi There, Time To Get Off For The Night Don't You Think?” and you have the choice between Yes and No, if you choose yes Windows will let you know that the system is scheduled for a shutdown with a full banner notification across the center of the screen, after you’ve closed that banner notification, you’ll see the fail-safe box prompting if you would like to cancel the shutdown in case you accidentally started the shutdown and didn’t mean to press yes, this is here just because sometimes we don’t think before we click and therefore having a fail-safe is always a good thing!

If you chose no on the 1st box Windows won’t do anything and the box will disappear so you can continue to work however if you chose no on the second box that appeared (The Fail-Safe Box) then you system will shutdown in 2 minutes.

So now you’re probably wondering, well, how would one go about scheduling this to run at a certain time every day? Well I’ll tell you, the secret is yet another Windows Program known as “Task Scheduler”. This piece of software allows you to schedule tasks to run as set times and even some programs you install on your system use task scheduler without you even knowing!

So let’s setup Task Scheduler to run your VBS file at a set time.

  1. Open the Task Scheduler program.

  2. On the right panel, under “Actions” and then under “Task Scheduler Library”, press “Create Task…”

  3. In the box that has now appeared, give your Task a Name, for example I’ve named mine “SleepTime” but you are free to name yours whatever you like! (If You Want To Give It A Description Too, You’re More Than Welcome To However This Is NOT A Requirement, It Is Purely OPTIONAL)

  4. Under “Security Options” ensure that the box “Run only when the user is logged on” is checked. At the bottom where it says “Configure for:”, Select the drop down box and choose your current Operating System or the latest Operating System that shows up if you’re running the latest version of Windows.

  5. Move onto the “Triggers” tab and in the bottom left corner press “New...”. In this menu ensure that the “Begin the task:” drop down is set to “On a schedule”. In the settings box change the option to your preference, for me I have it set to “Daily” but you may only want it to run weekly. Then on the right side leave the “Start:” as it is but change the time to when you want it to run and to the right of that ensure you check the box for “Synchronize across time zones”. If you’ve chosen “Daily” then you’ll also get the option to choose when the task should recur, this should be left to “1 days” but again, this is all up to your personal preferences. In the “Advanced Settings” box, ensure everything is unchecked except the “Enabled” box, “Synchronize across time zones” box and the “Expire:” box. Alter the “Expire:” box to be something like 30/12/2099, time can be anything. This just means that the task won’t ever stop running until 2099 which is good because you can choose when you want to get rid of the task at any time! After you’ve done all that press “OK” and continue to Step 6.

  6. Under “Actions” this is where you’re going to select the .VBS file you downloaded.

    In the Actions Tab, press “New…”, set “Action:” to “Start a program” then in the “Settings” box, press the “Browse…” button and find the .VBS file you created at the start. Select it and press “Open” and you should now see the file’s location appear in the “Program/script:” box. You can now press OK on this box and continue to step 7!

  7. Under the “Conditions” tab ensure everything is unchecked or set that to your personal preference, for me however I would leave them all unchecked.

  8. Under the “Settings” tab, ensure that “Allow task to be run on demand”, If the task fails, restart every:” and “If the running task does not end when requested, force it to stop” are all checked. Next to the “If the task fails, restart every:” box ensure this is on “1 minute” and underneath that ensure that is set to “3 times”.

    Finally ensure that “If the task is already running, then the following rule applies:” is set to “Do not start a new instance”. Press OK after you’ve done all that and now it should all work perfectly. If not, reread over everything to ensure you’ve not missed anything, also test it after you’ve created the task by selecting the task within Task Scheduler, right clicking it and pressing “Run”. If the boxes appear then it’s all working as expected.

SOURCES (Thank You Very Much, You Wonderful People!):

I hope you enjoyed reading this and I hope it helped you with better time management and allowing you to not run over a specific time like a bed time for example.

Thank you for reading!

Ryan / ZenDeuo :)

0
Subscribe to my newsletter

Read articles from Ryan Harris directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ryan Harris
Ryan Harris