Introduction: Program Your PC to Turn Off Automatically by Asigning Which Time You Want It to Do That

hey, thats another instructabel taken from my daily life...

last time i had to download lots of software to my PC and i had to let it download overnight, i didnt want to keep my PC turned on all night long after finishing the downloads and at the same time i couldnt stay awake to wait for it to finish the downloads and turn it off! therefore i made a VBscript that allows the PC to turn Off automatically in an interactive way !, i assign the minutes the PC will be turned on before shutting down according to how much time the downloads will take, i give it some little extra time to turn off after the time required for download in case there may be any decrease in speed but at least i wont stay awake nor i will keep my PC turned all night long doing nothing! and the PC in this case will be interactive with the user as i added to it some voice and narration too!
therefore watch my instructabel!

and if you like plz put a comment!
thanks

Step 1: Start by Writing the Script...


open notepad, and write the following script into notepad:

Dim x
Dim y

set oShell = createobject("wscript.shell")
Set Sapi = Wscript.CreateObject("SAPI.SpVoice")

x = InputBox("Would you like to shutdown your PC after a preiod of time? answer: yes/no","AUTOMATIC SYSTEM SHUTDOWN! by SCRIPTmaster")

if x = "yes" then
y = InputBox("Enter time left for shutdown to occur automatically(time in minutes...):","AUTOMATIC SYSTEM SHUTDOWN!")
sapi.speak y + "minutes left for shutdown"
oShell.Run "shutdown.exe -s -t " & (y * 60) & " -f -c ""System is now set for automatic shutdown! do not wait for the downloads to finish, you can go to sleep! GOOD NIGHT! see u 2morow! >>>>to terminate this Automatic shutdown just rerun the script and type no"""

end if
if x = "no" then
sapi.speak "okay, as you wish good bye, script writen by Ayman Farhat the SCRIPTmaster"
oShell.run "shutdown.exe -a"
end if

Step 2: Detailed Description of the Code in the Script...

Dim x and Dim y ///declare the variables x and y responsible for the answer and the time respectively.

set oShell = createobject("wscript.shell") /// calls the OS shell and creates the object wscript.shell

Set Sapi = Wscript.CreateObject("SAPI.SpVoice") ///calls the windows SAPI and creates the object SAPI.SpVoice which is responsible for the speech in this script as it narrates to the user...

x = InputBox("Would you like to shutdown your PC after a preiod of time? answer: yes/no","AUTOMATIC SYSTEM SHUTDOWN! " ///calls the input where the user says if he wants to shut down his PC

if x = "yes" then /// is a branching statement
y = InputBox("Enter time left for shutdown to occur automatically(time in minutes...):","AUTOMATIC SYSTEM SHUTDOWN!") // if the user chooses yes then he is promted by another input to asign the time left for shutdown
sapi.speak y + "minutes left for shutdown" ///the windows SAPI reads the minutes left

oShell.Run "shutdown.exe -s -t " & (y * 60) & " -f -c ""System is now set for automatic shutdown! do not wait for the downloads to finish, you can go to sleep! GOOD NIGHT! see u 2morow! >>>>to terminate this Automatic shutdown just rerun the script and type no""" ///this is the shutdown statement which calls the system shutdown executable to launch and shuts the PC according to the given time which is in this case the variable y!
end if //ends the first if statement which is in this case yes

if x = "no" then //.another is statement responsible for the no answer
sapi.speak "okay, as you wish good bye, script writen by Ayman Farhat the SCRIPTmaster" ///the SAPI speaks to the user and tells him good bye
oShell.run "shutdown.exe -a" / /the shutdown.exe is called in this case and is told not to perform the shutdown by adding -a !
end if // end of the if statement!

that was a breif yet detailed description, know go to the next step to see what to do...

Step 3: Saving Your Script

after you have entered your script to notepad you have to save it,
click save, and in the place where you type the name of your file put the name of your file followed .vbs as shown in the figure...

Step 4: Run Your Script...

double click on the VB program you just saved and see the magic!
you will be first prompted by an input askig you wether you want to shut down or not as show in the figure. if you do not choose to shut down by typing no the program will end automatically...
if you choose to shutdown by typing yes you will be prompted by another input asking the number of minutes you want your PC to stay turned on as shown in the figure below.
and then the shutdown countdown will start
if you want to end that shutdown for any reason just rerun the program while the shutdown is taking place and type no and it will terminate autonomously!

So that was a solution for a problem that a lot of PC users suffer from! hope you liked my instructable
if you do, please leave a comment i will be so pleased to hear from you.
GOOD LUCK and GOOD NIGHT!

The Instructables Book Contest

Participated in the
The Instructables Book Contest