Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disk Defrag from a command prompt in 2000

Status
Not open for further replies.

TrentGreenawalt

Technical User
Jan 18, 2002
159
US
Does anyone know how to preform a disk defrag from a command prompt in Win 2000. I am trying to set all of my company's computers to do a defrag at 1:00am with the task manager. I have figured out how to do it in XP to great success but know I am stumpted with 2000. Help....
 
If you copy XP's defrag command to 2k, does it work?
 
Here is a .vbs file found on LangaList. copy the script to notpad and save as idedfrag.vbs. Use task schudler to set the time to run. works with win2k's defrager. Non-dos though.



Dim NumDrives, FSO, Drives, Count

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Drives = FSO.Drives
NumDrives = Drives.Count
NumDrives = NumDrives - NumDrives

Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3

For Each Drive in Drives
If Drive.DriveType = DriveTypeFixed then NumDrives = NumDrives + 1
Next

Set Drives = Nothing
Set FSO = Nothing

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "dfrg.msc"
WScript.Sleep 2000
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
WshShell.AppActivate "Disk Defragmenter"
Wend

do while (Count <= NumDrives)

wscript.sleep 300
WshShell.SendKeys &quot;%A&quot;
wscript.sleep 300
WshShell.SendKeys &quot;D&quot;

While WshShell.AppActivate(&quot;Defragmentation Complete&quot;) = FALSE
wscript.sleep 5000
Wend

WshShell.AppActivate &quot;Defragmentation Complete&quot;
wscript.sleep 300
WshShell.Sendkeys &quot;{RIGHT}&quot;
wscript.sleep 300
WshShell.SendKeys &quot;{ENTER}&quot;
wscript.sleep 500
WshShell.SendKeys &quot;{TAB}&quot;
wscript.sleep 500
WshShell.Sendkeys &quot;{DOWN}&quot;

Count = Count + 1

loop

WshShell.Sendkeys &quot;%{F4}&quot;

 
I should have mentioned in my earlier post that you can use the task scheduler with this program to set the defrag to run at whatever time you wish, a very small program only 48 Kb. Is an .exe file so there is no installation, no changes made to your system. Run the program do the configuring from the command prompt, the program automatically schedules it in Task Scheduler where you can check to see it is setup the way you want, or make changes there. Nice and simple.
 
Thanks Toonei, padge1, wolluf I tried all three of your ideas and none works completly. Toonei that file work when clicked on locally on a 2000 machine but not when you schedule it to run. It starts but just sits there and Idles and doesn't do anything. So I tried Padge1 file and that didn't do anything either and wolluf though a good idea that didn't work as well. SO know I just have to figure out how to schedule this thing to work. I believe it has something to do with whom I am logging in with Localcomputer\Administrator? What do you guys think?
 
zilla,
I'm sure you looked at this but here is the exact instructions for getting it to run.

Once installed (copied), the application may be scheduled. The easiest way to do this is via the command prompt 'AT' command:

at 21:00 /interactive /every:M,T,W,Th,F,S,Su &quot;autodefrag&quot;

This particular example will cause the defragmenter to run every day at 9:00pm.

In order to verify that the task was correctly scheduled, an maybe to test the installation use the 'Scheduled Tasks' icon in the Control Panel.

Command-line options

When executed without any command-line arguments it defragments each disk in turn. This allows the use of a very simple 'at' command to schedule it.

If a drive-letter is provided on the command-line then that drive, and that drive only, will be defragmented.

Zilla
Hope you can get it working, good program.
 
Toonie,

I appreciate all of your help but this still doesn't work. It has to do with what user I am logged into at that time. If the computer is logged out it never starts, but if I am logged into the machine I get an illegal user error. I have tried useing the admin of the computer as the user and it still doesn't work. We are running win 2000 in a 2000 server domain, so I wonder if that is stopping things? Being on a domain? I have no idea. My boss is pretty much at an end with this. Any other suggestions would be great!

Thanks a lot,
Zilla
 
i think it has to do with rights, when it comes to a domain u have to take care of that incombenient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top