Windows 2000 VBS Scripting

First, I don't know what I'm doing when it comes to scripting, which is why I am asking for help.

On a Windows 2000 Pro machine with all SPs and updates installed, I downloaded a VBS script which is supposed to run dfrg.msc and enter key commands to defrag the primary partition with no user intervention. Scheduled Tasks indicates that it has been running as scheduled, however the volume is not getting defragged. So I manually entered each command in the VBS script in order at the command line to determine where it is going wrong.

The second command in the script, "WshShell.Run "dfrg.msc"", is generating the error "wshShell.Run is not recognized as an internal or external command".

Is it possible to get this script to run on this machine?
Who is Participating?
You have to put the script in a file with .vbs extension and then execute the file...
(by clicking on it or running "wscript.exe <filename>.vbs" from command line)
Hello westone,

according to this thread on the same vbs it will not work on windows 2000

however there is a post to a windows 2000 solution
If you want something that works for Win2k in a scheduled task:

AutoDeFrag is a free command line based wrapper of the Win2k defrag command

hope this helps a bit
westoneAuthor Commented:
Thanks for link. Autodefrag is not working either. I have a dozen identical W2000 Pro machines, and neither the VBS script nor the Autodefrag executable work on any of them.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

i'm not at a w2k server now so no way to test this

but from the looks of the vbs files there it should be worth giving a go
This is the code I use on W2K and it works for me.  Contents of defrag.vbs:

set WshShell = CreateObject("WScript.Shell")

'Launch Defrag from the command line and wait for 2 seconds
WshShell.Run "dfrg.msc"
WScript.Sleep 2000

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

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

'1 Send keys to move to top of drive/partition table.
WshShell.SendKeys "{TAB}{DOWN}"
WScript.Sleep 501

'1 Send an ALT-A key to bring down the defrag menu
WshShell.SendKeys "%A"
WScript.Sleep 502

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

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

'1 Bring the Defragmentation Complete window to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 503

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

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

'End - Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 700

'End - Send an ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
westoneAuthor Commented:
That's the same script I downloaded from the net that was stated to work under Windows 2000. I downloaded it from the compu-docs link (same one bruintje provided earlier). It just doesn't work.

Is it correct that entering each command in the script at the command line should work same as if the script were running?
No, absolutely not.  Lines of a batch file can be entered on a command line, but VBScript is interpreted by cscript.exe or wscript.exe, not the command shell.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.