Asked by:
Registry read Time Zone Info differ when code build on 4.0 framework on host system win 7 64 bit

Question
-
Hi
I have created console app to test the my code , code behave different value when it build from 2.0 framework to 4.0 framework.
I wanna to read System Local time zone in English in multilingual system . so have read the registry value .Below are codes ---
string tzName ="";
tzName = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\TimeZoneInformation").GetValue("TimeZoneKeyName", "", RegistryValueOptions.None).ToString();
if (tzName == "")
tzName = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\TimeZoneInformation").GetValue("StandardName", "", RegistryValueOptions.None).ToString();This code works well when it build on 2.0 framework but in 4.0 framework it gives redundant value for e.g "GMT Standard Timetime" ,instead of "GMT Standard Time" , "Eastern Standard Timeard " instead of "Eastern Standard Time" , many other non character appended on time zone eg '/0' .
This only occur on win 7 64 bit , in win 8 its work fine
Please help me out as earliest as possible
Thanks
Paritosh Mishra
Wednesday, June 4, 2014 4:25 AM
All replies
-
Hi, I think you can try to use TimeZone.CurrentTimeZone.StandardName to get standard name
If you want to get more Time Zone Info, you can try TimeZoneInfo class.
Wednesday, June 4, 2014 8:23 AM -
Hi ,
Thanks for a quick response . My application support multilingual , therefore TimeZoneInfo class return string depends on system language .I need only English Local Time Zone as registry has.
below are codes I used but not worked when system has language other than english
TimeZoneInfo localZone = TimeZoneInfo.Local;
tzName = localZone.Id.Trim()The strange things that "Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\TimeZoneInformation").GetValue("TimeZoneKeyName", "", RegistryValueOptions.None).ToString();" this code worked in win 8 but not in win 7
and its also worked when build on 2.0 on win 7 but not in 4.0 ,win7
Please help me on urgent basis
Thanks for advance
Regards
Paritosh Mishra
Wednesday, June 4, 2014 1:48 PM -
Hi Paritosh,
Try the method on the following link. http://blogs.msdn.com/b/bclteam/archive/2007/06/07/exploring-windows-time-zones-with-system-timezoneinfo-josh-free.aspx.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Tuesday, June 10, 2014 8:23 AM -
I ran into the same problem, and found your question here via Google. Since none of the answers here addresses a basic point in your question (.Net 2 vs. .Net 4), I posted a question on Stack Overflow, and eventually got an answer there. It looks like what we have encountered is due to sloppy programming on the part of Microsoft combined with a change in how .Net 4 returns string data from the registry.
http://stackoverflow.com/questions/27716746/hklm-system-currentcontrolset-control-timezoneinformation-timezonekeyname-corrupFriday, January 2, 2015 6:15 AM