Script for Defraggler

I would like to create a script that would run the Defraggler Program

Defrag ALL Drives

Not From within Defraggler.

Any suggestions?

Cjoego
Joseph SalazarVice President - Senior IT ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Haresh NikumbhSr. Tech leadCommented:
0
Steven HarrisPresidentCommented:
If you want to keep it simple and flexible, create a .bat for CMD.

To perform on a specific volume:

defrag <volume> /U

Open in new window


To perform on all volumes:

defrag /C /U

Open in new window


Parameters:
 /A      Perform analysis on the specified volumes.
 /C      Perform the operation on all volumes.
 /E      Perform the operation on all volumes except those specified.
 /H      Run the operation at normal priority (default is low).
 /M      Run the operation on each volume in parallel in the background.
 /T      Track an operation already in progress on the specified volume.
 /U      Print the progress of the operation on the screen.
 /V      Print verbose output containing the fragmentation statistics.
 /X      Perform free space consolidation on the specified volumes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

BillDLCommented:
Are you talking about the Defraggler utility by Piriform, or about the in-built Windows defrag.exe?

http://www.piriform.com/defraggler

http://www.piriform.com/docs/defraggler

It comes as an installer which installs both the Windows GUI and the command line versions of the program.

Advanced use of DEFRAGGLER.EXE, including how to use a custom *.INI file to store program settings and how to run it from a USB Flash Drive:
http://www.piriform.com/docs/defraggler/advanced-usage
To create an INI file rather than have it use the Windows Registry: Settings menu > Options > Advanced > "Save Settings to INI file".

Command line options for DF.EXE:
http://www.piriform.com/docs/defraggler/advanced-usage/command-line-parameters
Command-Line.txt
You cannot defrag more than one drive at a time:
http://www.piriform.com/docs/defraggler/introducing-defraggler/what-it-can-and-cant-do

The most useful command line switch if using a batch file to "defraggle" one drive after another would be the /L switch to list volumes that it can "defraggle".  You should then be able to parse that information and set the drive letters as variables to use in a command that is repeated, or ones that run sequentially (consecutively).  I will look at it later if this is what is being asked about.
0
BillDLCommented:
If you were talking about Piriform Defraggler, then here is an example batch file that should work, but I have only tested it in Windows XP and have only allowed it to echo what it will do rather than actually run it on all the drives
@echo off
SetLocal EnableDelayedExpansion

REM Change this path if it is different on your computer.
set PROG=C:\Program Files\Defraggler\df.exe

REM Checks to make sure that the program is where the above path says it is.
if not exist "%PROG%" echo Defraggler Command Line Program Not Found. & pause & goto :EOF

REM Run the program with the /L switch to list accessible drives and exclude
REM the first few informational lines of what it would display.
REM For each line found, use only the first of the space-separated fields.
REM This will be the drive letter with the colon after it.
REM This  FOR  command is a loop that processes one line at a time, and
REM therefore one drive letter at a time before going on to the next.
REM Everything inside the brackets is the loop.  When there are no more lines
REM from the results of the program's /L switch, it finishes.

for /f "skip=3 tokens=1 delims= " %%A in ('call "%PROG%" /L') do (
    set DRIVE=%%A
    echo.
    echo Defraggling !DRIVE!
    echo call "%PROG%" !DRIVE! /QD
    echo.
    echo Finished Defraggling !DRIVE!
    echo.
    echo Press any key to continue with next drive, or Ctrl + C to exit ...
    pause > nul
)
echo.
echo.
echo FINISHED!
echo.
echo Press any key to quit ...
pause > nul

Open in new window

You can remove all the lines that begin with  REM  as they are only comments or "REMarks" for your information.

Note: As it is, this is only going to go through the steps involved with calling DF.EXE and will show the command on the screen.  It will not execute the command until you remove the   echo   at the start of the line:
echo call "%PROG%" !DRIVE! /QD

Additionally, you should also delete these lines inside the brackets for the process to continue without human intervention:

    echo.
    echo Press any key to continue with next drive, or Ctrl + C to exit ...
    pause > nul


I have used the "Quick Defrag(gle)" switch  /QD  for this example.

Warning:  I have absolutely no idea what will happen if the C: Drive is Defragg(l)ed while the batch file that called it is actually on that drive.  I would guess that it will just treat the batch file as an unmovable file, but if it interrupts the processing it could mess up the sequential flow of the batch file.

I would suggest that you run this on a test computer, or else make sure that the computer you use it on is well backed up.  I cannot accept responsibility for the program messing your computer up, although I have used this program in the Windows GUI mode without any issues.
0
Joseph SalazarVice President - Senior IT ConsultantAuthor Commented:
Thank you everyone

I will be using all of these,

Cjoego
0
BillDLCommented:
Thank you Cjoego
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Hardware

From novice to tech pro — start learning today.