What to do if your CMOS battery gets "tired" and the PC forgets the date?

The trivial answer would be: buy a new one. Smile But you should already know that I'm not a guy who goes for the most straight ahead solutions ... the trickier it gets, the better. Wink Lets see how we can solve this by using the Windows Time service and the time synchronization that I wrote about earlier.

The symptom is that the PC "forgets" all its CMOS settings after being turned off for a while. The most important among all the CMOS data is the clock ... moreover the current date and time. We can fix this by setting up a Windows job to sync the time at boot.

This requires two things:
  1. Setting up the scheduler.
  2. Further tweaking the Windows Time service.
Let's start with the scheduler. Windows has a service (see the Services management console) called "Task Scheduler". You can create tasks (or jobs), assign some scheduling to them and a number of parameters, and the OS will execute the jobs at the preset intervals/dates. First of all set the Task Scheduler service to "automatic" startup. Moreover we'll need a dependency between the scheduler service and the time synchronization service. This cannot be done through the GUI, you'll have to get your hands dirty by digging into the registry. Start the registry editor (regedit.exe), navigate to the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Schedule. Under the Schedule key there's a "DependOnService" value (with "REG_MULTI_SZ" data type). It should already have something in it ... eg. "RpcSs", which means that the scheduler service already depends on the "Remote Procedure Call (RPC)" service. Add to the end of this multi-string the "W32Time" value, so the scheduler depends also on the "Windows Time" service. This way you can be sure that the scheduler service will start only after the time service.

Now let's set up the synchronization job. Go to StartMenu/Settings/ControlPanel/ScheduledTasks/AddScheduledTask. Select the %SystemRoot%\system32\w32tm.exe program (where %SystemRoot% is most probably C:\Windows), select for the schedule "Perform this task: When my computer starts", enter credentials of an account (username+password) that the job should be run with, check the "Open advanced properties" checkbox and press "Finish". The job is now created and the advanced properties screen is opened for you. Here you should add the "/resync /nowait" switches at the end of the "Run" textbox, so it should show something like this: C:\WINDOWS\system32\w32tm.exe /resync /nowait.

Now we've the job, there's only one more thing to do. The Windows Time service is designed to be "fail-safe" in a way that it will not update your clock if the difference between the time-server and your time is larger than a preset value (15h by default). We should override this so it'll update the clock regardless of the difference of the clocks (since our CMOS clock is reset to some very old value after every boot ... mine is reset to some date in 1999). This can be done again in the registry. Go to the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config. Set the "MaxNegPhaseCorrection" and "MaxPosPhaseCorrection" values to 0xFFFFFFFF (which is the hexadecimal representation of the 4294967295 decimal number). This special value will turn off the limitation of the clock differences completely. Smile

Your're now all done and can test the result. If you're lucky (and didn't ruin your PC by digging in the wrong places of your registry Wink, which can be quite harmful if not done properly), then your PC will synchronize its clock after every boot without the need for a user logon. Smile