Configuration:
YesLetter:
If you use a non-english Windows, you might have to change the content of the variable "YesLetter". The command-line tool chkdsk needs a confirmation before starting. This is normally the first letter of the word "yes" in the systems default language (for example Y in english, J in German and so on)
ExitCommand:
By default (ExitCommand= ) the script ends with shutting the computer down/PowerOff. If you want to other software (for example for Suspend/ Hibernate instead of Shutdown), add the full path here.
Example:
ExitCommand=c:\WINDOWS\NOTEPAD.EXE.
LogFile, TimeStamp, PartingLine:
LogFile: Name of the log file
TimeStamp: Time and date, written into the logfile
PartingLine: Line to separate the logs from different Janitor-runs
Drives:
This script checks and defrags only drive C.
If you want to check other drives too, duplicate the following line:
runwait, cmd /c echo %YesLetter% | chkdsk.exe c: /f /x >> %Logfile%, , minand replace the C: with another drive-letter. Each drive needs an own line of code
If you want to defrag other drives too, duplicate the following line:
runwait, cmd /c defrag c: /v >>%Logfile%, , minand replace the C: with another drive-letter. Each drive needs an own line of code
How this script works:
This script uses command line tools "cmd", "defrag" and "chkdsk" shipped with windows. Syntax and parameters er described in the Windows help file.
Checkdisk should be performed before defrag. Checkdisk often requires rebooting. So how do I get the computer to remember the waiting defrag-task after a reboot? I solved this by using the fileappend-command to write a complete ahk-script into the Startup-folder. This script is launched after reboot. The first thing this script does is to delete itself from the Startup-folder again. The script's ghost in RAM launches the defrag-task and, after finishing, shuts down the computer.
WARNINGS , LIMITATIONS
1. I tested this script on 2 computers with Windows XP Home and it worked fine. I don't know if the command line tools "defrag" and "chkdsk" are identical on Windows 9x or Windows 2000. If not, the script won't work or do unexpected things.
2. A defrag-run can take very long time. It needed 2 hours for my (rather crowded) 20 GByte FAT32 harddisk! I am not sure if files can be damaged when aborting a defrag-run (maybe someone knows more about that?). I recommend patience or a rather small harddisk/partition when playing around with the script.
3. The script requires an administrator-account (chkdsk doesn't work with other accounts)
4. The Defrag-part of the script starts after logon. If you have to log on with a password, it won't run completely unattended. A workaround is to use "Autologon", provided by TweakUI. (Does anybody know a way to start software before logon?)
Boskoop
; --------------------------------------------------------------------- ; Name: XP_Janitor ; Author: Boskoop ; Datum: 21.8.2004 ; ; Language: english ; Platform: tested with XP Home ; AHK-Version: 1.0.35.16 ; #Includeable: ; ; Description: ; Starts first "checkdisk" and then "defragmentation" on harddisks. ; When finished, it shuts the computer down and turns the power off by default. ; If you want to suspend/hibernate the computer you can start another script/ ; software instead. ; --------------------------------------------------------------------- ; --------------------------------------------------------------------- ; -- Configuration: --------------------------------------------------- ; -------------------------------------------------------------------- YesLetter=Y ;First letter of the word for "Yes" in the systems default language ExitCommand= ;Full path of what you want to start when the script is finished. Shutdown, when empty Logfile=%A_Scriptdir%\JanitorLog.txt TimeStamp=%A_DD%-%A_MM%-%A_YYYY% %A_Hour%:%A_Min%`n PartingLine=`n`n****************************************************`n ; --------------------------------------------------------------------- ; -- Autoexecute: --------------------------------------------------- ; -------------------------------------------------------------------- Msgbox,1, , This computer will reboot in 10 seconds for checkdisk and defrag.`nTo abort press "Cancel", 10 IfMsgBox, Cancel Exit Fileappend,%PartingLine%%TimeStamp%, %Logfile% runwait, cmd /c echo %YesLetter% | chkdsk.exe c: /f /x >> %Logfile%, , min Gosub Write_DefragAll shutdown, 2 exit ; --------------------------------------------------------------------- ; -- Subroutines: --------------------------------------------------- ; -------------------------------------------------------------------- Write_DefragAll: ; Uses the "Fileappend"-command to write the following complete AKH-script(DefragAll.ahk) ; into the Startup-folder. ; DefragAll.akh deletes itself from the startup-folder, starts defragmentation and ; shuts the computer down. IfExist %A_StartupCommon%\DefragAll.ahk Filedelete %A_StartupCommon%\DefragAll.ahk Fileappend, ( Filedelete, %A_StartupCommon%\DefragAll.ahk SplashImage, , b fs18 x0 y0 CWFF0000, Defrag is running! runwait, cmd /c defrag c: /v >>%Logfile%, , min SplashImage,Off Gosub,ExitSub exit ExitSub: ExitCommand=%ExitCommand% If ExitCommand= { Msgbox,1, , Shutdown and Power Off in 10 seconds.``n To abort press "Cancel", 10 IfMsgBox, Cancel Exit IfMsgBox, Timeout Shutdown,9 IfMsgBox, OK Shutdown,9 } Else { Msgbox,1, ,%ExitCommand% will be executed in 10 seconds.``n To abort press "Cancel", 10 IfMsgBox, Cancel Exit IfMsgBox, Timeout Run, %ExitCommand% IfMsgBox, OK Run, %ExitCommand% } ),%A_StartupCommon%\DefragAll.ahk return