Defragmentation over Network??

Hello experts...

Could anyone help answer this question it possible to defragment C drives or i mean local drives over the network
without spending any $$$$ ..???

Cheers and Thanks
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.


> Could anyone help answer this question it possible to defragment
> C drives or i mean local drives over the network without spending any $$$$ ..???

You can use a script to defrag the drives, and then schedule that script to run on each computer, over the network.
I got the code from  Just copy that to a .VBS file, and schedule that to run on whichever computers you want.

Hope That Helps,

'This script launches defrag and sends keys to the UI in order to automate the defrag

set WshShell = CreateObject("WScript.Shell")

'Launch Defrag from the command line and wait for a second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000

'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Disk Defragmenter") = FALSE
      wscript.sleep 1000

'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200

'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200

'Send a D to start the defrag
WshShell.SendKeys "D"

'Wait until the defrag is completed - Check for window every 5 seconds
While WshShell.AppActivate("Defragmentation Complete") = FALSE
      wscript.sleep 5000

'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200

'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500

'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500

'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
It depends on your OS version (assuming it is a Windows version.)

This kind of task can be scheduled remotely using the Win2K/WinXP remote scheduling features, which I believe are controlled through a policy.  I haven't done it myself, but someone here must have...;^)  I don't know that it's necessary to set up a script.

Kick me if I'm all wet... ;)
Well, it SHOULDN'T be necessary to set up a script, but it is.  When Microsoft licensed the defrag tool, they crippled it so that it can't be run from a remote computer, so the original company can still sell their "server" version.  The users got totally screwed on that one.

But, that script automates the mouse clicks necessary to launch the program and run it, so it gets around their little ploy...

SolarWinds® VoIP and Network Quality Manager(VNQM)

WAN and VoIP monitoring tools that can help with troubleshooting via an intuitive web interface. Review quality of service data, including jitter, latency, packet loss, and MOS. Troubleshoot call performance and correlate call issues with WAN performance for Cisco and Avaya calls

AAaaaacccchhh, I should know better!


Also, from

Accepted Answer from ekspurt
Date: 07/12/2003 09:33AM CDT
 Accepted Answer  

This article does specify that dfrgntfs.exe and dfrgfat.exe cannot be scheduled, as expressed by kiranghag (thanks for the reminder).;en-us;Q227463

But there is a work-around.  My apologies, I had gotten a utility from the article below a few months ago, set the filename to defrag.vbs, and that's why I referred to it as such above.

Article describing how to schedule a Win2K defragmentation.

VB script code for this article (available through the article's  "Download the Code" link):


I stand corrected, and humbly bow out...
Anything that allows automation of a remote windows GUI should do the job. Sounds like ShineOn has provided his usual swath of URLs that should cover this.

ShineOn - As an EE Networking PE, would it be too much to ask for me to bug you about certain topics from time to time that might require some references from your obviously huge list of handy URLs?  If so, don't worry about posting your email address - netminder will share it with me if I reference a post from you where you indicate this is OK.

agbor1960Author Commented:
Is script my only possibility??? is there any GPO doing the job???
The--Captain -

You can ask me or bug me as much as you want...

Believe it or not, my list of handy URLs is because I know how Google and other search engines work, and can get what I'm looking for quickly.

I hate to give away my trade secrets, but being able to use the tools is part of being a good troubleshooter...

I guess I just know where to look, and how to ask the question, which gives me a bit of an edge in some instances.

To: The--Captain -

PE stands for something other than Physical Education in this venue...  What is a PE, if I may expose my ignorance?

(One of the things I've learned over the years is to ask questions that benefit not only myself, but others paying attention at the time the question is asked...)
isn't there a command line switch now?
c:\windows\defrag.exe c: /noprompt /q

 Networking PE

That's where each machine gets it's own Network Engineer (Personal Edition)
(usually found in Micro$oft environments)


Seriously, tho - what's PE in this context...?
Page Editor - an EE volunteer who facilitates things
jadedataMS Access Systems CreatorCommented:

I checked and chicagoan is right about there being a command line version for XP, but not for W2K.  So, the answer really depends on which you are using.

If you are using XP:
Like Chicagoan said:  There is a command line utilitity you can run.  You can even run it remotely.  Download this free utility: and then you can Defrag any XP machine on your network like this:
   1) Start -> Run
   2) psexec \\COMPUTERNAME defrag

If you are using W2K:
You'll need to use the script that I told you before in my original response.  But you can still copy that script to a remote computer, and then invoke it using the PsExec tool like I said before.


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
@chicagoan:  I looked at the source code for that utility, and it basically does the EXACT same thing that the script does, except it does it in C++.  The code is much bigger because it has to have code to send the right key messages to the right window to make it work, but the scripting host has an object that does that for you, so the code is much more simple.  Isn't that interesting?

let me hunt for one in quickbasic...
but i dont think there is a "defrag.exe" on a windows machine anymore...
so third-party utilities are the only solutions.
on 2000 it's dfrgntfs.exe, but a defrag.exe command line was added to XP and 2003
i ran dfrgntfs.exe,
it gives me a messagebox "commmand line operation of defrag is not supported."
you are correct, hence the question
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

From novice to tech pro — start learning today.