It’s always fun automating stuff using vbscript. As a DBA it’s an added advantage, if you know some scripting languages like VBS, Powershell etc. I assume you are familiar with the auto sleep mode available in TV, which turns it off after so and so minutes. We too have this kind of functionality in other home appliances like microwave, washing machine etc etc. Like wise, we need something for our personal computer also, to turn it off after a certain period of time. It’s useful when you have kept some process running in the background and you know the process will take approximately an hour to complete and you want the PC to be shutdown once the process is completed. Here is the small VB script to schedule computer shutdown process.
Dim x Dim y set oShell = createobject("wscript.shell") Set Sapi = Wscript.CreateObject("SAPI.SpVoice") x = InputBox("Would you like to shutdown your computer?"& vbNewLine &"Answer: y/n"& vbNewLine & vbNewLine &"To cancel a scheduled shutdown, enter (n)","AUTOMATIC SYSTEM SHUTDOWN!") if x = "y" then y = InputBox("Enter time in minutes.. "& vbNewLine &"Your system will be turned off automatically after the mentioned minutes from now") If IsNumeric(y) = True And y <> "" Then sapi.speak y + "minutes left for shutdown" oShell.Run "shutdown.exe -s -t " & (y * 60) & " -f -c ""System is now set for a scheduled shutdown!""" Else WScript.Echo "Invalid input. (Inputs should be numeric)" End If end if if x = "n" then sapi.speak "okay, Auto shutdown process is aborted" oShell.run "shutdown.exe -a" end if If x <> "n" And x <> "y" Then WScript.Echo "Invalid input, Inputs must be y or n for YES or NO" End If
Copy above codes into a text file, save the file with extension .vbs instead of default .txt