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?

[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.

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.
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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.
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)

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
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.