Does anyone have some code that will take a TimeZoneInfo field from .NET and execute the interop code to set the system time zone via SetTimeZoneInformation? I realize that it’s basically mapping the TimeZoneInfo members to the struct members, but it does not appear obvious to me how the fields will map exactly or what I should care about beyond the bias.
Share
I don’t know if this is what you are looking for, but there is some information on how to use the Win32 functions to get and set the timezone information at
http://www.pinvoke.net/default.aspx/kernel32/GetTimeZoneInformation.html
The main part of the following sample code is taken from this site. I just added a few more lines to actually call the GetTimeZone() method and fixed a small error in the access modifier of the SystemTime struct to make the sample work.
Hope this helps…
Before setting the time zone information you will need to ensure that the process has the appropriate privileges. As noted on the MSDN page for SetTimeZoneInformation:
Here is some sample code to enable this privilege: