PriTyan Posted February 20, 2004 Share Posted February 20, 2004 I have a VBScript that I have been running for a while on my 2000 Servers to automate Disk Defrag. This works great on 2000 Servers. See code below 'Automate Defrag for Windows 2000Dim Window, sysd, cmdset Window = CreateObject("WScript.Shell")sysd = Window.ExpandEnvironmentStrings("%defdrive%")cmd = "dfrg.msc %" & sysdWindow.Run cmdWScript.Sleep 1000While Window.AppActivate("Disk Defragmenter") = FALSE wscript.sleep 1000WendWindow.AppActivate "Disk Defragmenter"WScript.Sleep 1000Window.SendKeys "%A"WScript.Sleep 250Window.SendKeys "D"WScript.Sleep 250While Window.AppActivate("Defragmentation Complete") = FALSE wscript.sleep 5000WendWindow.AppActivate "Defragmentation Complete"WScript.Sleep 250Window.Sendkeys "{TAB}"WScript.Sleep 250Window.Sendkeys "{ENTER}"WScript.Sleep 250Window.Sendkeys "%{F4}"WScript.Sleep 250WScript.QuitHere is my problem on 2003 Servers. The below code waits for the pop-up window titled "Defragmentation Complete" to identify that the defrag has completed, then the rest of the code procedes to send keys to close out of defrag.While Window.AppActivate("Defragmentation Complete") = FALSE wscript.sleep 5000WendThe problem with 2003 defrag is that the title to the pop-up window that indicates Defrag has completes is the same as that Defrag app "Disk Defragmenter". So my problem is how do I identify the new pop-up window since it has the same name as the original window? See image below.I've contiplated just putting a long Sleep command, but would like my code to be a little cleaner. Any help would be appreciated. P Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now