Nice Beermonster,
I don't work with batch files as often as I probably could/should but this will definitely help a few people. I wonder if posting how to make a batch file might be helpful?
Quick and dirty:
- Open a Notepad window and copy the code from Beermonster's post.
- Goto File -> Save As
- Enter a file name and enter ".bat" at the end of the name
- Change "Save as file type" to All files
I still use batch files a fair bit, probably because:
a ) I learned to use computers with DOS and never got out of some of the habits.
b ) I use linux a lot and shell scripts are common.
So yeah kmiller has given what is probably the easiest way to write a batch file in windows. You could if you wanted just save it as a .txt and then change the extension to .bat and click OK when it warns you the file may become unusable.
Or you could do it the old fashioned way:
Open a command line (run "cmd" or navigate around the startbar, your choice).
Navigate to your Desktop folder (or any other folder you want to put the batch file in). You will usually start out in your home directory "C:\Documents and Settings\Yourusername" so to get to your desktop is a simple "cd desktop"
Now you want to start working on your defrag batchfile so "edit dfrgshtd.bat" (I have chosen to call it dfrgshtd.bat - you can pick whatever you want as long as the extension is .bat)
Nice eh?
Lovely blue background dos text editor.
Type in (or paste) the instructions:
"C:\Program Files\Defraggler\df.exe" C: && shutdown -s -t 1
Then save (Alt-F, S) and exit (Alt-F, X)
You can run the batch file by double clicking in windows or by typing it into the command line, you can even use the task scheduler of your choice to run it.
I will give a short description of what the batch file does and how you may wish to change it:
"C:\Program Files\Defraggler\df.exe" C:
this runs the command line version of defraggler "df.exe" and tells it to defrag drive C: you can read more about df.exe and the switches that can be passed to it in the defraggler documentation.
&&
this is an instruction to run the following command (shutdown) on successful completion of the preceding one (df).
shutdown -s -t 1
this runs the shutdown.exe program with the instruction to shutdown (-s) and to wait one second before doing so (-t 1)
I have made some choices here that you may wish to vary:
1. I am displaying the progress of the defrag, this is because I like to check how it is getting along if I'm passing, it also means that if defraggler bails out with an error message I can see it. If you do not wish to have the output displayed then insert a new line at the top of the batch file script and enter:
@echo off
on that line.
2. I am only shutting down the computer on successful completion of the defrag. If there's an error I don't want to shut-down. If you do want to shut-down even if it fails then you can replace the double ampersand (&&) with a single ampersand(&).
3. I am using a one second countdown before shutting down, this is because if I happen to be at the computer when the defrag finishes I'd like a chance to stop the shut-down. If you'd like more time give yourself more time, if you wouldn't then give a countdown of 0. If you don't specify a countdown the default is 30s.
4. I am actually shutting the computer down because I care about the planet and this is a home machine. You can instead of giving shutdown the -s switch use -r to restart the computer, -l to log off the current user.
Feel free to read around and adjust the script to your hearts content, pipe the output of df to a log file if you want, make it display animated asciiart as you wait, whatever, have fun!