PaulSadowski.com 

Windows Scripting Host
 VBScript To Determine Computer's TimeZone
This script displays the computer's timezone information (offset from UTC).

To display the TZ as the number of minutes from UTC set the constant frmMinutes to true. Setting this constant to false displays the TZ in the format [-][[h]h]:[mm]

-300
-5:00


One use of this script is to set a system timezone variable (TZ) at machine startup in the startup script or a similar user environment variable in individual user accounts login scripts. For example, in a user login file on W2K or XP:

for /f %%c in ('c:\bin\tz.vbs') do setenv -u TZ %%c

* setenv is a utility for setting environment variables. Do a web search to find a copy.




This script uses WMI (Windows Management Interface). WMI must be installed on Windows® ME and Windows® 9x. It is automatically installed on Windows® 2000, Windows® XP and Windows®.NET Server.

Note:
You can also set environment variables from within WSH scripts

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshSysEnv = WshShell.Environment("SYSTEM")
WshSysEnv("TZ") = "-300"

Set WshUserEnv = WshShell.Environment("USER")
WshUserEnv("TZ") = "-300"

Set WshProcessEnv = WshShell.Environment("PROCESS")
WshProcessEnv("TZ") = "-300"

Environment type can be either SYSTEM or PROCESS or USER except in Windows® 9x and Windows® ME where it can only be PROCESS.

 

Const frmMinutes = true

for each os in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
 if frmMinutes = false then
  Wscript.Echo os.CurrentTimeZone/60 & ":" & right("00" & os.CurrentTimeZone mod 60, 2)
 else
  Wscript.Echo os.CurrentTimeZone
 end if
next

© 2003 by Paul R. Sadowski   
All Rights Reserved. Used By Permission.  
Comments to: Scripting