Changing the system time zone succeeds once and then no longer changes
Posted
by Adam Driscoll
on Stack Overflow
See other posts from Stack Overflow
or by Adam Driscoll
Published on 2010-03-31T16:53:52Z
Indexed on
2010/04/01
15:03 UTC
Read the original article
Hit count: 355
I'm using the WinAPI to set the time zone on a Windows XP SP3 box. I'm reading the time zone information from the HKLM\Software\Microsoft\WindowsNT\Time Zones\<time zone name>
key and then setting the time zone to the specified time zone.
I enumerate the keys under the Time Zones key, grab the TZI
value and stuff it into a TIME_ZONE_INFORMATION
struct to be passed to SetTimeZoneInformation. All seems to work on the first pass. The time zone changes, no error is returned.
The second time I perform this operation (same user, new session, on login before userinit) the call succeeds but the system does not reflect the time zone change. Neither the clock nor time stamps on files are updated to the new time zone. When I navigate to:
HKLM\System\CurrentControlSet\Control\TimeZoneInformation
my new time zone information is present.
A couple strange things are happening when I'm setting my time zone:
- Also when I parse the TZI binary value from the registry to store in my
TIME_ZONE_INFORMATION
struct I'm noticing the struct has theDaylightDate.wDay
andStandardDate.wDay
field always set to 0 - I tried to call GetTimeZoneInformation right after I call
SetTimeZoneInformation
but the call fails with a 1300 error (Not all privileges or groups referenced are assigned to the caller. )
I'm also making sure to send a WM_BROADCAST
message so Explorer knows whats going on.
Think it's the parsing of the byte array to the TIME_ZONE_INFORMATION
struct? Or am I missing some thing else important?
EDIT:
Found a document stating why this is happening: here. Privilege was introduced in Vista...thanks MSDN docs...
Per the Microsoft documentation I'm enabling the SE_TIME_ZONE_NAME privilege for the current processes
token. But when I attempt to call
LookupPriviledgeValue for
SE_TIME_ZONE_NAME I get a 1313 error (A specified privilege does not exist. ).
© Stack Overflow or respective owner