[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 812
  • Last Modified:

Windows 2000 VBS Scripting

Hi,
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?
0
westone
Asked:
westone
1 Solution
 
bruintjeCommented:
Hello westone,

according to this thread on the same vbs it will not work on windows 2000
source: http://www.ureader.com/message/14011.aspx

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
source: http://www.morphasys.com/autodefrag/
----------

hope this helps a bit
bruintje
0
 
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.
0
 
bruintjeCommented:
i'm not at a w2k server now so no way to test this
http://www.compu-docs.com/W2KDfrag.htm

but from the looks of the vbs files there it should be worth giving a go
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smgcincCommented:
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
Wend

'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
Wend

'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}"
0
 
westoneAuthor Commented:
smgcinc,
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?
0
 
dlwyatt82Commented:
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.
0
 
everlaastCommented:
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)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now