Time Zone Question for Torgeir 
Author Message
 Time Zone Question for Torgeir

Torgeir,

I am trying to use a  script To get the time zone of a local machine. I
tried to find something in WMI and came up empty handed and then I found
your script (below) . What I would like to do is use something like your
script to get the Time Zone the machine is in and echo it or write it to a
file. Case Select I guess would do it, but I don't know how to get the
current machine time zone and then get it selected and displayed. Can you
help some with this? My machine is in the Central Time Zone.

Thanks
Jerry

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oRegistry = GetObject("winmgmts:root/default:StdRegProv")
sBaseKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)

For Each sKey In arSubKeys

  iRC = oRegistry.GetStringValue( _
          HKLM, sBaseKey & sKey, "Std", sValue)
  iRC = oRegistry.GetStringValue( _
          HKLM, sBaseKey & sKey, "Display", dValue)
    sValueTot = sValueTot & "TimeZone: " & _
 dValue & "  : " & sValue & vbCrLf

Next
WScript.Echo sValueTot



Wed, 02 Feb 2005 12:35:10 GMT  
 Time Zone Question for Torgeir
The registry key you gave lists all available time zones.
I find the current time zone setting in
HKLM\System\CurrentControlSet\Control\TimeZoneInformation

In that key, the value "Bias" is the number of minutes
West of GMT. In the Central time zone the value is 168 in
hex, or 360 minutes (6 hours). The value StandardName is
the name of the time zone, DaylightName is the name of the
daylight savings zone. In my case these are "Central
Standard Time" and "Central Daylight Time".

I use Bias. I have found that on some machines (W2k) the
value is type "REG_DWORD", which is VB type Long, on other
machines (Win9x) the value is type "REG_BINARY", which is
VB type Variant(). I use the following code to translate
the value to hours:

Set oShell = CreateObject("Wscript.Shell")
BiasKey = oShell.RegRead
("HKLM\System\CurrentControlSet\Control\TimeZoneInformation
\Bias")
If UCase(TypeName(BiasKey)) = "LONG" Then
  Bias = Round(BiasKey)/60)
End If
If UCase(TypeName(BiasKey)) = "VARIANT()" Then
  Bias = 0
  For k = 0 To UBound(BiasKey)
    Bias = Bias + (BiasKey(k) * 256^k)
  Next
  Bias = Round(BiasKey/60)
End If

Maybe you don't want to round off, to handle the crazy
time zones where the bias is in 30 or 15 minute increments.

Richard

Quote:
>-----Original Message-----
>Torgeir,

>I am trying to use a  script To get the time zone of a
local machine. I
>tried to find something in WMI and came up empty handed
and then I found
>your script (below) . What I would like to do is use
something like your
>script to get the Time Zone the machine is in and echo it
or write it to a
>file. Case Select I guess would do it, but I don't know
how to get the
>current machine time zone and then get it selected and
displayed. Can you
>help some with this? My machine is in the Central Time
Zone.

>Thanks
>Jerry

>Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
>Set oRegistry = GetObject

("winmgmts:root/default:StdRegProv")
Quote:
>sBaseKey = "SOFTWARE\Microsoft\Windows

NT\CurrentVersion\Time Zones\"

- Show quoted text -

Quote:
>iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)

>For Each sKey In arSubKeys

>  iRC = oRegistry.GetStringValue( _
>          HKLM, sBaseKey & sKey, "Std", sValue)
>  iRC = oRegistry.GetStringValue( _
>          HKLM, sBaseKey & sKey, "Display", dValue)
>    sValueTot = sValueTot & "TimeZone: " & _
> dValue & "  : " & sValue & vbCrLf

>Next
>WScript.Echo sValueTot

>.



Wed, 02 Feb 2005 22:29:56 GMT  
 Time Zone Question for Torgeir

Quote:

> I am trying to use a  script To get the time zone of a local machine. I
> tried to find something in WMI and came up empty handed and then I found
> your script (below) . What I would like to do is use something like your
> script to get the Time Zone the machine is in and echo it or write it to a
> file. Case Select I guess would do it, but I don't know how to get the
> current machine time zone and then get it selected and displayed. Can you
> help some with this? My machine is in the Central Time Zone.

Hi

You will need to read registry values placed under this key:

HKEY_LOCAL_MACHINE
\SYSTEM
\CurrentControlSet
\Control
\TimeZoneInformation

For some theory/documentation:

----------------------------------------------
See tip 0398 at 'NT Reg Hacks' at http://www.jsiinc.com/reghack.htm for
documentation on them.

----------------------------------------------

Subject: Time zones
Date: 1998/01/16
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=779a79...

----------------------------------------------

Subject: Changing sytem time/time zones
Newsgroups: microsoft.public.windowsnt.misc
Date: 1999/10/05
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=341570...

Some script code from other threads:


Subject: Re: timezone
Newsgroups: microsoft.public.scripting.VBScript, microsoft.public.scripting.wsh
Date: 2002-04-15 17:30:20 PST

Quote:
> HKLM\System\CurrentControlSet\Control\TimeZoneInformation
> contains the current timezone

> HKLM\Software\Microsoft\Windows\CurrentVersion\Time Zones
> contains all available timezones

> i'm not able to find out how this timezone thing works. i'm lost...
> can somebody help me solve this problem.

Here's a VBScript that formats date/time in UTC format.  You can use this as a
starting point...

msgbox FormatUTC(now)

function FormatUTC(ByVal vDate)

'================================================
  'Converts input date/time to Universal Time
  'Coordinate (UTC) in the same format as JScript's
  'Date().toUTCString() method.
  '
  ' dayabbreviation, dd monthname yy hh:mm:ss UTC
  '
  'Example: Fri, 2 Jul 1999 18:17:50 UTC
  '

'================================================
  if isdate(vdate) then
    vdate = cdate(vdate)
  else
    err.raise &h7001,"FormatUTC","Argument is not a valid date"
  end if

  set shell = createobject("wscript.shell")

  'ActiveTimeBias is the number of minutes that UTC
  'is offset from local time.  It is added to local
  'date/time to get UTC equivalent.
  '
  strValueName = _
    "HKLM\SYSTEM\CurrentControlSet\Control\" _
    & "TimeZoneInformation\ActiveTimeBias"
  tmpTimeOffset = shell.regread(strValueName)

  'ActiveTimeBias can be REG BINARY or REG DWORD
  'depending on the OS version...
  '
  if IsArray(tmpTimeOffset) then
    'it's REG BINARY w/ 2 bytes significant
    lngTimeOffset = tmpTimeOffset(0) + (tmpTimeOffset(1)*(2^8))
  else
    'it's REG DWORD
    lngTimeOffset = tmpTimeOffset
  end if
  dt = DateAdd("n", lngTimeOffset, vDate)

  'Extract the "fields" of the date/time and
  'reformat into UTC standard format.
  '
  dayabbr = weekdayname(weekday(dt),True) 'abbreviated

  'JScript doesn't include leading 0 on day,
  'so we don't either.
  '
  dd = datepart("d",dt)
  monnm = monthname(month(dt),true)
  yyyy = year(dt)

  hh = right("00" & hour(dt),2)
  mn = right("00" & minute(dt),2)
  ss = right("00" & second(dt),2)

  FormatUTC = _
      dayabbr & ", " _
    & dd & " " & monnm & " " & yyyy & " " _
    & hh & ":" & mn & ":" & ss _
    & " UTC"

end function
</qoute>

- and -

<qoute>
Subject: Re: Making Calls to Windows System Information
(Time Zone Info) from VBScript?
Date: Tue, 16 Apr 2002 04:42:29 -0600

Newsgroups: microsoft.public.scripting.vbscript

Here is a routine I use to get Timezone Offset by reading the Registry.

'Read time zone offset hex value from Registry.
Dim ws, TZOffset, HexVal
Set ws = CreateObject("WScript.Shell")
TZOffset = ws.RegRead("HKLM\SYSTEM\CurrentControlSet\" & _
           "Control\TimeZoneInformation\ActiveTimeBias")

'Reg value format varies between Win9x and NT
If IsArray(TZOffset) Then
  'Win9x uses a reversed 4 element array of Hex values.
  HexVal = Hex(TZOffset(3)) & Hex(TZOffset(2)) & _
           Hex(TZOffset(1)) & Hex(TZOffset(0))
Else 'Must be a NT system.
  HexVal = Hex(TZOffset)
End If

'Convert to minutes of time zone offset.
TZOffset = - CLng("&H" & HexVal)

MsgBox TZOffset & " minutes offset from GMT"

</qoute>

--
torgeir



Wed, 02 Feb 2005 23:36:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Time zone question

2. Time zone - Newbie question

3. Time & Time Zones

4. time zones and daylight saving time

5. Formatting Time to GMT when current Time Zone not known

6. Real time From Time Zone information

7. Daylight saving - winter time - summer time - time zone

8. Daylight saving - winter time - summer time - time zone

9. Daylight saving - winter time - summer time - time zone

10. Time Zone Question?

11. Time Zone Question

12. Determining Time Zones or Server Time

 

 
Powered by phpBB® Forum Software