Lookup current Timezone via registry index?

  • Thread starter Thread starter stephen clover
  • Start date Start date
S

stephen clover

Lookup current Timezone via registry index?


Hi, I've got a problem I don't seem to be able to solve and after much
googling, I've decided to ask here.

OS: Windows 2000 (hopefully will work for as many of (9x, Me, NT, XP) as
possible too)
Compiler: MSVC++ 6.0

I want to add functionality to an app so that it knows the current timezone
of the machine that it is running on, so it can work out if its config files
were saved in a different timezone. The problem I cannot solve is that I
need to 'learn' the current time-zone. There seems to be no straightforward
way to do this. It must be possible though because the time/date/timezone
applet (double-click time in SysTray) as well as the resource-kit TzEdit
utility both know how to build a list of available timezones and highlight
the current one.

I can do the first bit by enumerating the table of timezones in the Time
Zones registry key (located in HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Time Zones), but I can't find a way to determine which of
the timezones is currently selected.

I have monitored registry calls while the timezone applet and TzEdit run and
they only appear to enumerate the Time Zones key. This surely means they
are using either (a) an API call or (b) something in the results of the
enumeration to tell them which is currently selected.

In the Time Zones key there is an array of NULL-terminated strings called
IndexMapping. Each of the Time Zones subkeys has a DWORD value called
Index. I can't find any reference to what these are used for.

The current-timezone registry key
(HKLM\System\CurrentControlSet\Control\TimeZoneInformation) holds a number
of values which are basically what you get in the returned data from the
GetTimeZoneInformation() API call. There's nothing else which hints at an
index number.

The international-settings registry key (HKCU\Control Panel\International)
has a value called Locale which contains a number (in my case 00001409). I
can find this number in the IndexMapping array (maybe a 'lucky'
coincedence), but there doesn't seem to be any significance about the
location in the array which leads me to an entry in the table of timezones.

Surely there must be a way to do this, which doesn't involve stepping
through the timezones table and comparing the TZI value of each to the
results of GetTimeZoneInformation. Is there? Can anyone shed some light on
this?

stephen/.
 
Back
Top