Windows Tip: Shutdown Your Computer With A Batch File
Written by Saman Sadeghi on January 21, 2007 Add comments
Why Shut the Computer Down Later?
I have my computer set to defragment itself at 2am but I don’t want it running all night! So, I wrote a batch file that will shutdown the computer and set a Scheduled Task (in the Control Panel) to run the file at 3am.
How To Use The Task Scheduler To Shut the Computer Down At A Later Time
Create a new batch file and write a shutdown command. All you really need is:
cd\
shutdown -s -t 60
I set the “-t” switch just in case I am on the computer and need to cancel it (I shouldn’t be on it at 3am, but you never know). At this point, you should test the file to make sure it’s working.
Save the file, I prefer to save my batch files in the Programs Files folder in the c:\ drive. They are program after all!
Schedule The Task
- Navigate to: Control Panel -> Scheduled Tasks -> Add Scheduled Task

- Hit Next in the dialog box that opens.
- In the second screen, navigate to the location of the file.

- We’ll set this to only run one time, we can change this later (in the Advanced Properties) if we want.

- Enter the time and date you want it to run.

- In the next screen, enter in the user name and the password.

- Hit Finish and you’re done!

You can go into the Advanced Properties, but you don’t really need to.
Start Slide Show with PicLens LiteMegaman Loves These Related Posts:
[...] trick is very similar to shutingdown your computer with a batch file, we just need to change the switch that we pass! More information on the shutdown command and [...]
THANKS FOR THIS
And to cancel shutdown countdown enter this at Start | Run or at cmd prompt:
shutdown -a
You’re right - Thanks for the tip!
it dos not work in XP
It absolutely works in Windows XP Pro - I haven’t checked “Home” because it’s a joke - also, check to make sure that you followed the directions correctly!
yeha it doesnt work in home
i have it and it says it couldnt be done
It dose work in home. I am using it now.
the easiest way to solve such a defrag-problem is to run the defrag with a batchfile, and then to let the computer shut down by the same batch.
could look like this:
@echo off
defrag c: -f
defrag d: -f
defrag e: -f
.
.
.
defrag xy: -v
shutdown -s -t 5
first it defrags the c-drive, after that the d-drive …blah blah
the ‘-f’ forces to do the defrag, a ‘-v’ instead is for ‘volunteer’. then windows only defrags, when it is needful. (if it is not needful, it makes strange errors, which are absolutely harmless) so the ‘-f’ is better.
after having defrag’d the drives windows shuts itself down. in this case here after 5 seconds, could be 0 or three, or fivehundred…, too.
sorry for third-class-english,
jaunda…
Though I didn’t see anyone asking about defragmentation, you are right! Also, I did write an article on this as part of my Start Your Day With A Fresh Computer series, which you can read here: Step Three: Automate Hard Drive Defragmentation.