Hi guys,

we're have been relying on the Timezone information inside the Windows registry pretty heavily.
To identify the time zones, we have used the index that is stored in the registry.

However, we have now found several problems with that:

  • In Windows Vista, the index no longer exists and we couldn't find any definite way to identify each zone.
  • Depending on which version of Windows (Server and Client) our application is running on, there are different time zones in the registry. Some zones only exist in XP, but not on the server.

When searching the internet for a secure way to rely on the info, always the same piece of code shows up.
This is how we have used this piece of code so far:

ArrayList zones = new ArrayList();
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"))
{
   string[] zoneNames = key.GetSubKeyNames();
   foreach(string zoneName in zoneNames)
   {
      using(RegistryKey subKey = key.OpenSubKey(zoneName))
      {
         try
         {
            TimeZoneInformation tzi = new TimeZoneInformation();
            tzi.name = zoneName;
            tzi.displayName = (
string)subKey.GetValue("Display");
            tzi.standardName = (
string)subKey.GetValue("Std");
            tzi.daylightName = (
string)subKey.GetValue("Dlt");
            tzi.index =
Convert.ToInt32(subKey.GetValue("Index").ToString());
            tzi.initTzi((
byte[])subKey.GetValue("Tzi"));
            zones.Add(tzi);
         }
         catch (Exception ex) { }
      }
   }
}

TimeZoneInformation[] availableZones = new TimeZoneInformation[zones.Count];
zones.CopyTo(availableZones);
Array.Sort(availableZones);

However, this piece of code won't work on Vista or Server 2003 Enterprise...

Any ideas what info one should rely on when using Timezones?

Thanks,
Stitch