I've found a script and tested this solution who works
fine!
So copy this script on notepad and give him the name
autodefrag c.vbs and use the task scheduler to start it
at the
time you want.
The script for disk C is:
-------------------------------------------------------
-----
'This script launches defrag and sends keys to the UI in
order
to automate the defrag
'process.
set WshShell = CreateObject("WScript.Shell")
'Launch Defrag from the command line and wait for a
second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
'Wait until the defrag is completed - Check for window
every
5 seconds
While WshShell.AppActivate("Defragmentation Complete")
=
FALSE
wscript.sleep 5000
Wend
'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
'Send a tab key to move the focus from View Report
button
to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
-------------------------------------------------------
-----
The script for disk D: is:
-------------------------------------------------------
-----
'Ce script lance la défragmentation du disque C sous
windows
2000
'par l'envoi de combinaison de touches ŕ l'interface
utilisateur.
set WshShell = CreateObject("WScript.Shell")
'Lancement du défragmenteur et attente de 1 seconde
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
'Passage de la fenętre du défragmenteur en avant plan
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
'Envoi de la touche TAB pour passer dans la zone
sélection de
disque du défragmenteur
WshShell.SendKeys "{TAB}"
WScript.Sleep 200
'Envoi de la touche Fleche vers le bas pour sélectionner
le 2e
disque dur ŕ défragmenter
WshShell.SendKeys "{DOWN}"
WScript.Sleep 200
'Envoi de la combinaison de touches ALT+A pour ouvrir le
menu Action
WshShell.SendKeys "%A"
WScript.Sleep 200
'Envoi de la touche D pour lancer la défragmentation du
2e
disque
WshShell.SendKeys "D"
'Wait until the defrag is completed - Check for window
every
5 seconds
While WshShell.AppActivate("Defragmentation Complete")
=
FALSE
wscript.sleep 5000
Wend
'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
'Send a tab key to move the focus from View Report
button
to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
'Ce script lance la défragmentation du disque C sous
windows
2000
'par l'envoi de combinaison de touches ŕ l'interface
utilisateur.
set WshShell = CreateObject("WScript.Shell")
'Lancement du défragmenteur et attente de 1 seconde
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
'Passage de la fenętre du défragmenteur en avant plan
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
'Envoi de la touche TAB pour passer dans la zone
sélection de
disque du défragmenteur
WshShell.SendKeys "{TAB}"
WScript.Sleep 200
'Envoi de la touche Fleche vers le bas pour sélectionner
le 2e
disque dur ŕ défragmenter
WshShell.SendKeys "{DOWN}"
WScript.Sleep 200
'Envoi de la combinaison de touches ALT+A pour ouvrir le
menu Action
WshShell.SendKeys "%A"
WScript.Sleep 200
'Envoi de la touche D pour lancer la défragmentation du
2e
disque
WshShell.SendKeys "D"
'Wait until the defrag is completed - Check for window
every
5 seconds
While WshShell.AppActivate("Defragmentation Complete")
=
FALSE
wscript.sleep 5000
Wend
'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
'Send a tab key to move the focus from View Report
button
to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
-------------------------------------------------------
----
You can change or adapt these script to launch another
application by sending command key to the UI. Take a
look on
this link for the command keys:
http://www.devguru.com/Technologies/wsh/quickref/wsh
shell_
SendKeys.html
Logged In: NO
This sucks!
Logged In: NO
Worked Great! Thanks!