Geeks With Blogs
David Douglass .NET on My Mind

What I’ve seen in most corporate environments is that PCs are up all the time; at the end of the day people either just log off or lock the machine.  You can take advantage of this to reset Windows every night for best performance the next day.  I’ve found three things make for a useful reset:

  1. defragmenting the hard drives
  2. booting the machine
  3. defragmenting the system files that are skipped in step 1

This can be done by modifying the ScheduledDefrag task that comes with later versions of Windows or creating such as task in XP and 2003.  In Vista, you’ll find Microsoft’s task in the Scheduled Tasks snap-in at Task Scheduler Library –> Microsoft –> Windows –> Defrag –> ScheduledDefrag.  The first step is to change it to a daily schedule and make sure it’s enabled:

image

Next, the action Microsoft supplies should be changed.  Microsoft’s action is "%windir%\system32\defrag.exe –c –i" (Vista).  -c is for all drives, but what is –i?  It’s undocumented but defrag is happy to accept it.  In testing, it seemed to cause defrag to run much slower, and my guess it’s i for idle, in other words, run only when the machine is idle.  So, I’d like to change the action to "%windir%\system32\defrag.exe –c –v > c:\Logs\defrag.log 2>&1", but that doesn’t work because the scheduler calls CreateProcess, which doesn’t interpret the redirection request.  If you run the command using the shell the redirection will work.  In that case Program/script is set to CMD Add arguments (optional) is set to "/c %windir%\system32\defrag.exe g: -v > c:\Logs\defrag.log 2>&1" (without the quotes).

image

While this works, it’s not my preferred  solution since all actions will require this clumsy setup with CMD.  Instead, write a DOS script with all the work, in which case redirection works as it should:

image

We’ll take a look at the DOS script after a couple of more adjustment to Microsoft’s task.  Waiting for the machine to go idle is unnecessary, so remove that:

image

Having the task run as soon as possible if the scheduled time is missed is unnecessary and causes it to run on boot or after resuming from hibernation.  Clear Run task as soon as possible after a scheduled start is missed:

image

The script simply does the defrag and a reboot:

date /t
time /t
%windir%\system32\defrag.exe -c -v
date /t
time /t
shutdown /r /d P:4:1 /t 300 /c "daily automated reboot"

The shutdown command says to restart the machine (/r), that this is a planned shutdown (/d P:4:1), to wait 300 seconds before performing the shutdown (/t 300), and to enter a comment in the event log (/c “daily automated reboot”).  If you happen to be logged in when this runs, you be informed that a shutdown is about to take place.  At that point you have 300 seconds to abort the shutdown by running the DOS command shutdown –a.

The steps above cover defragging the drives and rebooting the machine, but some files won’t be defragged because Windows is using them when defrag runs.  To defrag those, you need to defragment as part of the boot process.  For 32 bit systems, I recommend Sysinternals PageDefrag.  Download the program, run it, and make sure Defragment every boot is selected:

image

Unfortunately, PageDefrag doesn’t work on 64 bit systems.  In that case I recommend UltraDefrag.  UltraDefrag is a general purpose defragmenter (like Microsoft’s defrag) and also does boot time defragmentation (on 32 or 64 bit systems).  After downloading UltraDefrag, run the GUI console, call up the settings, and check Enable:

image

The script that ships with UltraDefrag assumes that your operating system is on the C drive; if not, press the script button and change the drive.  See http://ultradefrag.sourceforge.net/handbook/Boot.html for more information

Speaking of UltraDefrag, you may want to consider using it in place of Microsoft’s defrag.  The net is full of talk that defrag isn’t very good at what it does and that UltraDefrag and MyDefrag are better choices.

Posted on Sunday, July 4, 2010 12:35 PM | Back to top


Comments on this post: Windows Daily Reset

# re: Windows Daily Reset
Requesting Gravatar...
nice thing u posted
Left by rajesh on Jul 04, 2010 1:06 PM

# re: Windows Daily Reset
Requesting Gravatar...
This is very useful. At least even with PC left on all night, it is actually doing something that will be of benefit the next day.
Left by Columbus Laptop Repair on Apr 18, 2011 4:07 PM

Your comment:
 (will show your gravatar)


Copyright © David Douglass | Powered by: GeeksWithBlogs.net