Problem Setting TimeZone with SetTimeZoneInformation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helloitsme
    New Member
    • Oct 2006
    • 20

    Problem Setting TimeZone with SetTimeZoneInformation

    Hello All!

    I know there already exists a thread with this topic by Mike! But my problem did not get solved with that....

    I have a working code in VB6 that can set the selected timezone for the system. When i converted that code in VB .NET, I am having a problem similar to what Mike was having. When I select my timezone to Eastern Time Zone (or SA Pacific), my code sets my system timezone to 'Bogota, Lima, Quito'. i guess it is becoz both these timezone have GMT - 5.00 as their times. and perhaps due to some day light setting difference, which is not being conveyd propoerly to the SetTimeZoneInfo rmation function, the system get the 'Bogota' timezone instead of the 'EST'.

    As Mike had pointed out, my code does have the StandardName and DayLightName settings correct. (I compared these values with the working VB6 code).

    Does anyone have any clue about this...the code part doing this is -

    Code:
     lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SubKey & "\" & List1.Text, 0, KEY_ALL_ACCESS, hKeyResult)
    
            If lRetVal = ERROR_SUCCESS Then
               
                lRetVal = RegQueryValueEx(hKeyResult, "TZI", 0, 0, rTZI, Len(rTZI))
    
                If lRetVal = ERROR_SUCCESS Then
                    TZ.Bias = rTZI.Bias
                    TZ.StandardBias = rTZI.StandardBias
                    TZ.DaylightBias = rTZI.DaylightBias
                    TZ.StandardDate = rTZI.StandardDate
                    TZ.DaylightDate = rTZI.DaylightDate
                   
    
                    cbStr = 32
                    dwType = REG_SZ
    
                    lRetVal = RegQueryValueEx(hKeyResult, "Std", 0, dwType, bytSTDName(0), cbStr)
    
                    If lRetVal = ERROR_SUCCESS Then
                        Call MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, bytSTDName(0), cbStr, TZ.StandardName(0), 32)
                    Else
                        RegCloseKey(hKeyResult)
                        Exit Sub
                    End If
    
                    cbStr = 32
                    dwType = REG_SZ
    
                    lRetVal = RegQueryValueEx(hKeyResult, "Dlt", 0, dwType, bytDLTName(0), cbStr)
    
                    If lRetVal = ERROR_SUCCESS Then
                        Call MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, bytDLTName(0), cbStr, TZ.DaylightName(0), 32)
                    Else
                        RegCloseKey(hKeyResult)
                        Exit Sub
                    End If
    
                    If TZ.DaylightDate.wMonth <> 0 And TZ.DaylightBias <> 0 Then
                        lRetVal = SetTimeZoneInformation(TZ)
                    Else
                        Call CopyMemory(TZ.DaylightName(0), TZ.StandardName(0), 64)
                        TZ.DaylightBias = 0
                        lRetVal = SetTimeZoneInformation(TZ)
                    End If
    thank you for your time...
Working...