How to turn on auto adjust for daylight savings using a VBscript

Daylight savings changes can often pose a problem for IT support professionals. Usually these issues arise when governments decide to change daylight savings rules or your organisation operates in multiple time zones. A common problem often encountered is the computers clock doesn’t adjust for daylight savings time. This can occur because either the wrong time zone is selected or the “Automatically adjust clock for Daylight Saving Time” is deselected in the time zone settings. For example the Queensland time zone may be selected for a Hobart computer which means the time will be correct until daylight savings kicks in and then the time won’t adjust.
In the first example the solution is to change the computer to the correct time zone. In the second example the solution is to simply select the “Automatically adjust clock for Daylight Saving Time” option, but what if you need to apply the setting to multiple Windows computers? The answer is to use a script via group policy or other method.
The following simple script will re-enable daylight savings.

Option Explicit
on error resume next

'Constants used to specify which hive to write to
Const HKEY_CLASSES_ROOT 	= &H80000000
Const HKEY_CURRENT_USER 	= &H80000001
Const HKEY_LOCAL_MACHINE 	= &H80000002
Const HKEY_USERS 		= &H80000003
Const HKEY_CURRENT_CONFIG 	= &H80000005
'Constants used to specify write type
Const REG_SZ        = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY    = 3
Const REG_DWORD     = 4
Const REG_MULTI_SZ  = 7
Dim objReg

Const RegPath = "SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
Dim strComputer
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
objReg.DeleteValue HKEY_LOCAL_MACHINE,RegPath,"DisableAutoDaylightTimeSet"
objReg.DeleteValue HKEY_LOCAL_MACHINE,RegPath,"DynamicDaylightTimeDisabled"

Line 22 connects to the standard registry provider for the computer, which gives us access to the method to delete registry keys and values. Depending on the version of Windows the computer is running, the registry values we are concerned with is either “DisableAutoDaylightTimeSet” or “DynamicDaylightTimeDisabled”. Lines 23 and 24 just attempt to delete these values. Deleting these registry entries sets the time zone back to default which is automatically adjust for daylight savings time. If the registry value doesn’t exist the line “on error resume next” ensures the script continues, making the script compatible with multiple versions of Windows.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks

1 thought on “How to turn on auto adjust for daylight savings using a VBscript

Leave a Reply

Your email address will not be published. Required fields are marked *

*