SetTimeZoneInfo unable to read the timezone name for the next time

Pertanyaan SetTimeZoneInfo unable to read the timezone name for the next time

  • Tuesday, April 24, 2012 9:03 AM
     
     

    Hi All

    I have used SetTimeZoneInfo to change time zone of my system.

    The date and time is changed according to the timezone i have chosen.

    But , in the Timezone settings dialog box, it says "Your current time zone is not recognized. Please select a valid time zone."

    Because of this , i'm not able to read the system time zone for the next time.

    I tried changing in the registry too. even then i'm facing the same problem.

    The registry path i used is : "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"

    and "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\TimeZoneInformation"

    Can anyone help me in this regard please.

    Thanks in advance.

    • Moved by Helen Zhao Thursday, May 03, 2012 2:10 AM Qt Issues (From:Visual C++ General)
    •  

All Replies

  • Tuesday, April 24, 2012 9:22 AM
     
     

    Can you show the code?

    -- pa

  • Tuesday, April 24, 2012 9:45 AM
     
     

    QString RegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
        QSettings settings(RegKey, QSettings::NativeFormat);
        QStringList childKeys = settings.childGroups();
        int i = 0;
        QString strStdName;    
        for (QStringList::iterator it = childKeys.begin();it != childKeys.end(); ++it)
        {
             QString strtimeZone = RegKey + "\\" + *it;
             QSettings settings1(strtimeZone, QSettings::NativeFormat);
             QString str = settings1.value("Display",0).toString();
             strStdName = settings1.value("Std",0).toString();
             if(str == strDisplayName)
             {
                QString RegKey1 = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
                QString newRegKey = RegKey1 + "\\" + strStdName;
                LPCWSTR lpString = newRegKey.utf16();
                if( RegOpenKey(HKEY_LOCAL_MACHINE,lpString,&hk) == ERROR_SUCCESS)
                {
                    dwType = REG_SZ;

                    if( RegQueryValueEx(hk,L"TZI",0, &dwType, (BYTE *) &binary_data, &size) == ERROR_SUCCESS)
                    {
                        tz.Bias = binary_data.Bias;
                        tz.DaylightBias = binary_data.DaylightBias;
                        tz.DaylightDate = binary_data.DaylightDate;
                        tz.StandardBias = binary_data.StandardBias;
                        tz.StandardDate = binary_data.StandardDate;
                        QSettings settingsTimeZone(newRegKey, QSettings::NativeFormat);
                         muiStd = settingsTimeZone.value("MUI_Std").toString();
                         muiDlt= settingsTimeZone.value("MUI_Dlt",0).toString();
                         muiDisplay= settingsTimeZone.value("MUI_Display",0).toString();
                    }
                    break;
                }

             }
         }
        RegCloseKey(hk);


        bStatus =  SetTimeZoneInformation(&tz);
        if( !SetTimeZoneInformation( &tz ) )
        {
            qDebug("STZI failed (%s)\n", GetLastError());
            return 0;
        }

        QSettings settingsTimeZoneCurrent("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation" , QSettings::NativeFormat);        
        QSettings settingsTimeZoneCurrent001("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\TimeZoneInformation" , QSettings::NativeFormat);        

        settingsTimeZoneCurrent.setValue("TimeZoneKeyName",strStdName);
        settingsTimeZoneCurrent.setValue("StandardName",muiStd);
        settingsTimeZoneCurrent.setValue("DaylightName",muiDlt);
        settingsTimeZoneCurrent001.setValue("TimeZoneKeyName",strStdName);
        settingsTimeZoneCurrent001.setValue("StandardName",muiStd);
        settingsTimeZoneCurrent001.setValue("DaylightName",muiDlt);

        if(bStatus == false)
        {
            DWORD dwErrorCode = GetLastError();
            return false;
        }

        // Disable the privilege

        tkp.Privileges[0].Attributes = 0;
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);

    strDisplayName is the name of the TimeZone which will come from UI.

                 

  • Wednesday, April 25, 2012 6:28 AM
     
     

    hi

    I have given the code too....

    can u help me in this regard pls

    Thanks in advance

  • Wednesday, April 25, 2012 9:01 AM
     
     

    Hi Bujju,

    I have been watching on this thread for a while now. Could you please let us know which platform you are programming on? It seems that the codes are not of standard VC++.

    If it is a Qt application, I suggest you refer to Qt Forum for better support: http://qt-project.org/forums/.

    I am looking forward to your quick response.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, April 26, 2012 5:36 AM
     
     

    Hi Helen,

    As you stated, yes, it is Qt application.

    But , I'm using c++ WIN API to implement this.

    Only writing into the registry , i used Qt classes.The registry entry is also updated correctly. I want to know what else i have to do to get the timezone name correctly for the next scenario.

    But , in the Timezone settings dialog box of windows 7 , it says "Your current time zone is not recognized. Please select a valid time zone." 

    Any help would be greatful.
  • Thursday, May 03, 2012 2:09 AM
     
     

    Hi Bujju,

    According to your lat reply, I suggset you go to Qt Forum for better support:http://qt-project.org/forums/. In Visual C++ General forum, we only discuss general questions about Visual C++, so this thread will be moved to Off-Topic Posts.

    Thanks for your understanding.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us