Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Batch file to de-fragment, backup, then shutdown?

08 Apr 2012   #1

Windows 7 Home Premium SP1 x64
Batch file to de-fragment, backup, then shutdown?

Hey guys,

Is there a way I can create a batch file so de-fragment my hard drive, once that has finished, backup to an external hard drive, and then one that has finished shut down the PC?



My System SpecsSystem Spec
08 Apr 2012   #2
Microsoft MVP

Windows 7 Ult. x64


The first two are easy enough, but I've had some trouble getting a SHUTDOWN to happen after a backup has run - it seems to execute the shutdown during the other commands.

For the defragmentation and backup, try this - lets assume you want to backup from E:\Work and E:\Music to Z:

defrag E: /U /V
robocopy E:\Work Z:\Backup\Work /E /MIR /R:3 /W:10
robocopy E:\Music Z:\Backup\Music /E /MIR /R:3 /W:10
To see more help with these commands, in a CMD window type:
defrag /?
robocopy /?
shutdown /?
And some light bedtime reading:
ROBOCOPY - Create Backup Script

My System SpecsSystem Spec
08 Apr 2012   #3

Windows 7 Ultimate x64

Maybe prepending the last robocopy command with start /wait would prevent that shutdown before the backup is finished.
My System SpecsSystem Spec


 Batch file to de-fragment, backup, then shutdown?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar help and support threads
Thread Forum
shutdown in batch file requires Administrator
Hi all, I've been using GFI Backup 2009 for backups for a while, it does everything I want, and sends email reports after backup is complete. One of its features is to shutdown the computer after a backup, this rarley works, as it wont shutdown if a program is already running, including GFI...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Protected Folders Batch File Backup
So I am trying to create a batch file that will copy certain folders from the My Documents and Program Files 86 folders. Of course these are protected. I can make a batch file and use robocopy to copy other files just fine. How can I set admin privileges? Or whatever it is I need to do to make it...
Backup and Restore
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Shutdown PC w/ batch file (1hour) after program(game) launched
Is it possible to do this? I want to make it so that a game shuts down the computer after "X" seconds/minutes/hours of playing the game. But i want the file to be somewhat undetected. I don't want it popping up with a message saying things like "PC will shutdown in 3 minutes" or anything like that...
Chillout Room
Auto shutdown batch file help
Happy new year everyone, I'm looking to create a batch file to auto shut down my machine after a certain amount of time. Just want to check if i have got the 1st part of the command right in notepad but i was not sure how i go about putting in a timer for example if my download has 2hrs left i...
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 19:00.

Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App