Solved

scheduling disk defragmenter

Posted on 2002-07-12
15
289 Views
Last Modified: 2010-04-13
I am trying to schedule a task to automatically defrag my servers e: drive on a daily basis.  I have the task done, but it only opens up the Disk Defragmenter program.  How do I get it so that it starts to defrag the e drive.

Is there a command line switch that I need to add for it to start defragging?

thanks
plucki
0
Comment
Question by:plucki
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 50 total points
Comment Utility
No, you can't do that without purchasing another defragmenting program.  Microsoft licensed the defrag program in 2000 from Executive Software.  In order to schedule defrags, you must purchase the defragment program from Executive software (or a competing product) in order to automate defrags
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
http://www.execsoft.com/consumer/diskeeper/diskeeper.asp

From the above link:
The built-in defragmenter that comes with Windows® must be run manually on one drive at a time. Diskeeper can be set to run automatically and will work on all the drives on your system. While the built-in is running, you won’t be able to run other programs. There is no interruption when Diskeeper is running. Diskeeper also defragments important system files that the built-in can’t handle.
0
 
LVL 7

Expert Comment

by:jmiller47
Comment Utility
Although it was thought that you cannot do this, you can!

With a little help from scripting that is!

Schedule this script to run at whatever time you want using Scheduled tasks, but make sure to run it under an Administrator's account.

http://www.pc-pipeline.com/modules.php?op=modload&name=Downloads&file=index&req=viewdownloaddetails&lid=5

You may be weary about just using a VBScript you don't know anything about, so please feel free to open it up in Notepad and check it out! It tells what each line does and you can tell a bit about what it does by looking at the code.

Have fun, and if you have any questions, let me know!
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
you will need to edit the script, specifically the line that reads:

WshShell.Run "dfrg.msc"

(it's near the top of he script)

The line, for your purposes, should read:

WshShell.Run "dfrg.msc e:"

0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
At first I was excited to see this script.  But it's highly incomplete.  I could try to modify it myself, but I'm not sufficiently proficient in WSH to be confident I could.  So if you want to program something that allows command line options and takes into account the possible errors that would occur, then this is a solution.  For example, IF you are prompted by the program that you don't have sufficient space to defrag, the defrag will never take place and the MMC console with defrag in it will remain open until you take action.

This is a reasonable workaround, but for a truly easy, most likely, painless or nearly painless system, you sould buy the product.
0
 
LVL 7

Expert Comment

by:jmiller47
Comment Utility
Correct. This program is ONLY for scheduling and automating the Windows Built-in Defrag, such as the question was asking for. As far as a Defragmentation solution for your computers, Diskeeper is your best bet.

Many companies cannot afford such luxuries so scheduling an automated task is their only alternative.

leew,

You say to use dfrg.msc e. What is the "e" for".

You say that is is highly incomplete. What is incomplete about it?

Thanks
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
plucki's question was to defrag his e: drive.  Executing the script as is will only defrag the c: drive.  

There are at least two things I would do to make this an effective script (but again, I don't think I have the confidence in my programming skills to be certain I can accomplish it).

1.  Accept command line input (switches).  Make it so that "defrag2k <driveletter>:" can be used.  In addition, make an "/All" switch so that all hard drives would be defragmented.

2.  There is no facility to handle warning messages, especially when the drive you defrag is low on disk space.  The script assumes no error/warning messages will appear.  When they do, it will essentially hang the script.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
Well Joel the script is pretty good. I have ran it several times and when it works it does what it is intended to do. However using SendKeys has some inherent problems. For example the system could throw a message about something that has nothing to do with defrag and the message could become the foreground window especially if it is an "Always on Top" type of window. So this would throw the script off its course so I suspect one would need to almost always do a

WshShell.AppActivate "Disk Defragmenter"

before activating SendKey.

Also sometimes something in the background could cause a delay in such way that the timing of the SendKey could be disrupted. It happened once when I ran this script and the defrag never took place. Please understand I am not being critical but rather just trying to pass on some info to you.

When I used VB I had a lot of experience with using SendKey and I found that it couldn't always be relied on to do its thing so to speak. Too many things can get in the way that prevents SendKey from getting to its intended target. I now write apps and use handles and/or server objects for the windows involved that I am wanting to interact with. Although this is much more complicated approach it has been a more reliable approach.

Also note I am not saying plucki won't find this script useful because it does have its benefits one of which it doesn't cost any money. And it does work if everything goes smoothly. :>)
0
 
LVL 7

Expert Comment

by:jmiller47
Comment Utility
I could be wrong here, but running this as a scheduled task, you run it as a different user as the one you are.

You are just running the script by most likely double-clicking on it. If you run it as s scheduled task, it will run as a different user and not lose the focus. The programs you are running may interfere with the focus. Run as a scheduled task, it doesn't seem to...

I also highly suggest using Diskeeper, but if you can't and need to use the script.

I will however look it over a bit more and see if it can be modified.

Thanks

OH! I just noticed that this is running on a server and not a workstation. I HIGHLY suggest purchasing the Diskeeper application then. It will be really be the only thing that will effectively defragment everything. You really need to use that. I don't have anything against scheduling defrag on a workstation, but NOT on a Server!


0
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
Joel just so you know I ran the script in the scheduler. I don't need to have my disk defraged but once every three months or so but I was curious to the effectiveness of the script so I shceduled it on two different mahcines to run once a day and 3 times out of 21 tries the defrag didn't happen. And on both mahcinies it was the admin account that the task was ran under. One time the defrag menu was never activated. Another time the system threw a message not concerning defrag but something else and the defrag did not run. The third time defrag froze up for some reason.
0
 
LVL 7

Expert Comment

by:jmiller47
Comment Utility
Then I would not use it. I haven't had any problems with it, but if it is having problems on other tests, I would go against using it. Please let me know of any of any ideas you may have or report any problems you find with the script I provided at the following Forum Topic:

http://www.pc-pipeline.com/cgi-bin/forums/index.php?act=ST&f=30&t=14&s=8a0a4a1b009a804298b9882eb21b3b7e

If I find something that is stable enough to use, I will post it here also. Thank You very much!

BTW, CrazyOne. The site mentioned above is my own free informational site. http://www.pc-pipeline.com. I have been very happy with all of the information you have put in posts here and if you would ever want to write articles or use my site to keep information, downloads, links, etc... Please contact me and I will set you all up. This site is strictly a free site for System Administrators to come to find helpful information and ask and have questions answered. Any help is always welcome!
0
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
Ok I should clarify. I am curious sort of person so I was just doing some field testing mainly. I think the script has merit and I was testing it so as to decide whether I would recommend it to other people. And I would recommend it for the causual user. I personally don't need it because my disk rarely gets fragmented enough to even warrant running defrag but once every two or three months. :>)

BTW thanks for the invitation and I will see if I can come up with something to contribute to your site. :>)

Sorry plucki for getting off topic.
0
 

Expert Comment

by:AdamMcLaurin
Comment Utility
I've been using OO Defrag for a couple years now, and I'm very happy with it. It has support for scheduled defrag, and can even do 'stealth' defrag so you can slowly defrag while working on the machine ..

http://www.oosoft.de/english/products/oodefragv4/index.html

The professional license isn't too expensive ($54.95 USD) ..
0
 

Expert Comment

by:AdamMcLaurin
Comment Utility
I've been using OO Defrag for a couple years now, and I'm very happy with it. It has support for scheduled defrag, and can even do 'stealth' defrag so you can slowly defrag while working on the machine ..

http://www.oosoft.de/english/products/oodefragv4/index.html

The professional license isn't too expensive ($54.95 USD) ..
0
 

Author Comment

by:plucki
Comment Utility
Thank you all for your input, after much testing with sendkeys, I've decide to buy Diskeeper.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now