Home All Groups Group Topic Archive Search About

How to change computer's "Time Zone" from vb.net

Author
30 May 2006 8:38 AM
Michael Barrido
please help.
I want to be able to change my computer's system "Time Zone" via vb.net
code. is it possible?

-mike

Author
31 May 2006 9:15 AM
gene kelley
On Tue, 30 May 2006 16:38:04 +0800, "Michael Barrido"
<jm***@hotmail.com> wrote:

>please help.
>I want to be able to change my computer's system "Time Zone" via vb.net
>code. is it possible?
>
>-mike
>

The short answer is "Probably".

I had an old example of this written in VB6 for use in Win98.

The basis of the example uses the API, SetTimeZoneInformation which,
in Net, would be:

Public Declare Function SetTimeZoneInformation _
        Lib "kernel32" (ByRef lpTimeZoneInformation _
        As TIME_ZONE_INFORMATION) As Integer

However, the old TYPE definition for TIME_ZONE_INFORMATION would not
be valid for NT systems and NET.

Public Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type

You would need to update this to a valid working Structure.  I found 3
different versions using a quick "google", with this one looking the
most ominous:

   Public Structure TIME_ZONE_INFORMATION
        Dim Bias As Integer
        <VBFixedString(64), System.Runtime.InteropServices. _
          MarshalAs(System.Runtime.InteropServices. _
        UnmanagedType.ByValTStr, SizeConst:=64)> _
         Public StandardName As String
        Dim StandardDate As SYSTEMTIME
        Dim StandardBias As Integer
        <VBFixedString(64), System.Runtime.InteropServices. _
        MarshalAs(System.Runtime.InteropServices. _
         UnmanagedType.ByValTStr, SizeConst:=64)> _
        Public DaylightName As String
        Dim DaylightDate As SYSTEMTIME
        Dim DaylightBias As Integer

    End Structure

TimeZone definitions for a given system are found in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time
Zones


Theoretically, you should be able to set the system time zone to any
one of those named Time Zones.

Long answer: Yes, but would depend on you NET skill level.


Gene