I have a legacy VB6 app I need to get working on Vista. The app needs to
synch with the Chicago stock exchanges, and to ensure there are no date/time
issues, I use the GetTimeZoneInformation and SetTimeZoneInformation APIs to
set the clock on the client machine to Eastern Standard Time.
This is working well on all versions of Windows up to and including Server
2003. However, Vista's time zone just will not change. As far a I can tell,
the API calls are succedding (in that all of them are returning
ERROR_SUCCESS (0) when called), so it looks like either the final Call
SendMessage(HWND_TOPMOST, WM_TIMECHANGE, 0, ByVal 0) is either not being
recognised or is being ignored (for 'security' reasons?) by Windows.
Anyone?
TIA
Rob
>I have a legacy VB6 app I need to get working on Vista. The app needs to
>synch with the Chicago stock exchanges, and to ensure there are no
[quoted text clipped - 8 lines]
> SendMessage(HWND_TOPMOST, WM_TIMECHANGE, 0, ByVal 0) is either not being
> recognised or is being ignored (for 'security' reasons?) by Windows.
So you're changing the user's time zone to accommodate your app? If that's
the case, you'd get a VERY nasty letter from me. It's developers doing crap
like that why MS is basically forced to toughen Windows with additional crap
like UAC (or in this specific case, require "special" privileges for the
function).
Why I'm providing any help at all is beyond me because I strongly disapprove
of what you're doing (if in fact you're really changing the user's time
zone), but in any event, did you read the remarks in the documentation for
the WM_TIMECHANGE message? They state:
--
An application should not broadcast this message, because the system will
broadcast this message when the application changes the system time.
Windows Me/98/95: An application should send this message to all top-level
windows after changing the system time using the SendMessageTimeout function
with HWND_TOPMOST. Do not send this message by calling SendMessage with
HWND_BROADCAST.
--
Furthermore, if you read the docs for SetTimeZoneInformation:
--
An application must have the SE_TIME_ZONE_NAME privilege for this function
to succeed. This privilege is disabled by default. Use the
AdjustTokenPrivileges function to enable the privilege before calling
SetTimeZoneInformation, and then to disable the privilege after the
SetTimeZoneInformation call. For more information, see Running with Special
Privileges.
Windows Server 2003 and Windows XP/2000: The application must have the
SE_SYSTEMTIME_NAME privilege.
--
My guess is that under WinXP/2000 and Server 2003, Admins have the
SE_SYSTEMTIME_NAME privilege and it's Admins that are using your app.
However, I would implore you to change your app to account for time zone
differences internally (so it doesn't have to change the time zone). Your
app (and you) really have no business, or right, to change a user's time
zone.

Signature
Mike
Microsoft MVP Visual Basic
Robert Bruce - 26 Jul 2007 14:27 GMT
>>I have a legacy VB6 app I need to get working on Vista. The app needs to
>>synch with the Chicago stock exchanges, and to ensure there are no
[quoted text clipped - 14 lines]
> additional crap like UAC (or in this specific case, require "special"
> privileges for the function).
<...>
Thanks Mike. The time zone stuff was originally included at the request of
the user (according to the documentation I have). As I said, it's a legacy
app, I'm only the maintenance guy.
I genuinely appreciate your thoughts - it had occurred to me also that since
I'm getting time zone information, and I know how to calculate time
differences, I really should change the app to do all of this stuff
internally. I think that's what I'm going to do - even if I find a way
around this via API calls, the chances are that it would be through the kind
of loophole that MS would want to close in the future.
Thanks again
Rob
Last time I checked, Chicago was in the Central Time Zone.

Signature
Steve Easton
>I have a legacy VB6 app I need to get working on Vista. The app needs to synch with the Chicago stock
>exchanges, and to ensure there are no date/time issues, I use the GetTimeZoneInformation and
[quoted text clipped - 11 lines]
>
> Rob
After changing the timezone (tut tut), you are supposed to call SendMessage
with the first parameter set to HWND_BROADCAST (NT / 2K / XP / 2K3 / Vista).
HWND_TOPMOST is for Windows 95/98/ME only. Your code should not have ever
worked.
>I have a legacy VB6 app I need to get working on Vista. The app needs to
>synch with the Chicago stock exchanges, and to ensure there are no
[quoted text clipped - 14 lines]
>
> Rob