Jump to content

Defrag and shutdown unattended


T_Beermonster

Recommended Posts

I was just reading through these forums and have noticed quite a few people wanting to run an unattended defrag and have their computer shut-down on successful completion.

 

I have a batch file on my desktop that I use to do this on my Windows XP box:

 

 

"C:\Program Files\Defraggler\df.exe" C: && shutdown -s -t 1

 

 

Obviously you may need to edit this to suit the location you have defraggler installed, which drive(s) you want to defrag and how long a delay you'd like between a successful defrag and the shut-down signal.

 

I believe that in vista shutdown.exe is present but the switch has changed from "-" to "/" (so "shutdown /s" instead of "shutdown -s") but you can check that yourself since I don't have Vista.

Link to comment
Share on other sites

I was just reading through these forums and have noticed quite a few people wanting to run an unattended defrag and have their computer shut-down on successful completion.

 

I have a batch file on my desktop that I use to do this on my Windows XP box:

 

 

"C:\Program Files\Defraggler\df.exe" C: && shutdown -s -t 1

 

 

Obviously you may need to edit this to suit the location you have defraggler installed, which drive(s) you want to defrag and how long a delay you'd like between a successful defrag and the shut-down signal.

 

I believe that in vista shutdown.exe is present but the switch has changed from "-" to "/" (so "shutdown /s" instead of "shutdown -s") but you can check that yourself since I don't have Vista.

 

 

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:

 

 

  1. Open a Notepad window and copy the code from Beermonster's post.

  2. Goto File -> Save As

  3. Enter a file name and enter ".bat" at the end of the name

  4. Change "Save as file type" to All files

 

There's always an exception to the rule. I'm that exception.

 

Desktop ----- AMD Athlon 3700+ (2.64Ghz), 2GB DDR 400, ASUS A8N-SLI Premium, 500GB HD, Windows XP Pro SP3, Avira Antivir Personal

At work ----- Intel C2D T1700 (1.6Ghz), 2GB DDR2 667, Dell OUY141, 80GB HD, Windows XP Pro SP2, Symantec 10

Laptop ----- Intel C2D P8400 (2.4 Ghz), 4GB DDR3 1066, Mainboard, 160GB HD, Dualboot: Windows 7/openSUSE 11.1, Avira Antivir Personal

 

link1.gif

Link to comment
Share on other sites

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:

 

 

  1. Open a Notepad window and copy the code from Beermonster's post.

  2. Goto File -> Save As

  3. Enter a file name and enter ".bat" at the end of the name

  4. 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!

Link to comment
Share on other sites

Nice thorough review Beermonster :) You obviously know your way around DOS and batch files ;P

There's always an exception to the rule. I'm that exception.

 

Desktop ----- AMD Athlon 3700+ (2.64Ghz), 2GB DDR 400, ASUS A8N-SLI Premium, 500GB HD, Windows XP Pro SP3, Avira Antivir Personal

At work ----- Intel C2D T1700 (1.6Ghz), 2GB DDR2 667, Dell OUY141, 80GB HD, Windows XP Pro SP2, Symantec 10

Laptop ----- Intel C2D P8400 (2.4 Ghz), 4GB DDR3 1066, Mainboard, 160GB HD, Dualboot: Windows 7/openSUSE 11.1, Avira Antivir Personal

 

link1.gif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.