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 Community Contributor Award Recipient

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

Similar help and support threads for2: Batch file to de-fragment, backup, then shutdown?
Thread Forum
Solved How to run a batch file at logoff & some batch scripting help please Backup and Restore
Protected Folders Batch File Backup Backup and Restore
Solved Batch File that grabs file names from folder to insert into batch file General Discussion
Creating .batch to run at shutdown Performance & Maintenance
Shutdown PC w/ batch file (1hour) after program(game) launched Chillout Room
Solved Auto shutdown batch file help 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 09:23.
Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App