Schedule Hard Drive Defrag through Logon Script
Hello again,
Recently I had a need to schedule a monthly defrag on all of the client machines in one of the networks that I manage. As usual, finding an efficient way of centrally deploying such a task is much easier than going to each machine and manually creating the task. I accomplished this by editing the SBS_LOGIN_SCRIPT.bat that is present on all SBS 2003 servers by default. Of course, if you are not in an SBS environment, you can apply this to any other login scripts that you may already have or create a new one and deploy it through Group Policy.
For my purposes, I needed a defrag to run automatically monthly on all machines so I used an app called schtasks.exe that is already installed on all 2000/XP machines. You can read the syntax by typing “schtasks /?” at the command prompt. Below is the line I added to my login script.
schtasks.exe /create /SC MONTHLY /D 20 /TN DefragMonthly /TR “C:\Windows\System32\defrag.exe\”C: -f” /ST 00:45:00 /SD 06/01/2009 /RU SYSTEM
Now, let me explain that as it may look cryptic..
/create – Indicates you are creating a scheduled task.
/SC – Specifies the Schedule Frequency (MONTHLY in this case).
/D – The Day of the month is should run (the 20th of each month in this case).
/TN – The Task Name (MonthlyDefrag in this case).
/TR – Task Run specifies the task to be ran or the application to be executed (”C:\Windows\System32\defrag.exe\”C: -f” in this case ((defrag.exe /? for more info on this))).
/ST – Start Time is the Hour at which the task should start in 24 hour format.
/SD – The Start Date, pretty self explanatory.
/RU – The user to run the task as (SYSTEM in this case – Must be SYSTEM or and Administrator).
After adding the above line to the Login Script, a new scheduled task will be added to the machines that run the login script. You can then wait until after the schedule was set to be run and check if it ran.
That is it for now..
DigitalKid (Jason)
www.954network.com

August 25th, 2009 at 12:02 am
uvatipikyl…
Drow Language Translation …
September 25th, 2009 at 10:04 am
lahirigigy…
gory crash photos …