Win XP Defrag Script question

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Win XP Defrag Script question

Post by ukdboyd » Wed May 25, 2005 6:13 pm

Hello all,

Trying to figure out how to get this script to close the Defrag program when it finishes. Here's what I have so far:

ExecuteFile>C:\WINDOWS\system32\dfrg.msc
WaitWindowOpen>Disk Defragmenter
Press ALT
Send Character/Text>ad
release alt

This all works fine. However, when the defrag finishes, a window pops up (titled Disk Defragmenter) asking if I want to analyze or close. How do I wait until the defrag is over (which could be minutes or hours) and then press the appropriate key and close the program. I want to be able to schedule this overnight and complete automate the process, with no dialog screens left open.

Thanks.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed May 25, 2005 10:12 pm

Use another WaitWindowOpen> command, waiting for the prompt window.and then use a PushButton> or similar command to select the button and finish it.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Post by ukdboyd » Thu May 26, 2005 9:17 pm

Bob Hansen wrote:Use another WaitWindowOpen> command, waiting for the prompt window.and then use a PushButton> or similar command to select the button and finish it.
I can't get this to work, and I think the reason is that the 2nd window that pops up has the same title as the first "Disk Defragmenter". Therefore, any WaitWindowOpen command happens immediately.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu May 26, 2005 11:41 pm

Try something like this (window names are no good here):

Code: Select all

//Wait for prompt window actions
Let>WF_TYPE=3
WaitWindowOpen>DiskDefrag*
SetFocus>DiskDefrag*
PushButton>.......
WaitWindowClosed>DiskDefrag

//Wait for prompt window to finish, then close main window
Let>WF_TYPE=1
SetFocus>Defrag*
Press ALT
Press F4
Release ALT
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

ukdboyd
Newbie
Posts: 11
Joined: Wed May 25, 2005 6:09 pm

Post by ukdboyd » Fri May 27, 2005 4:44 pm

I ended up going a completely different way with this. Fortunately Defrag offers a command line utility that works nicely.

Let>RP_Wait=1
Run Program>defrag c:
Let>RP_Wait=1
Run Program>defrag d:

This seems to work fine. I never could get the other script to properly recognize the pop up dialog, close it and then close the Windows defragmenter. Plus this one will work for multiple drives, whereas the other script would only work for the C: drive (I think).

Thanks.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri May 27, 2005 6:42 pm

Well done.

Note that you do not need to repeat RP_WAIT=1.
It will stay = 1 until you do RP_WAIT=0.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts