Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Time Zone

Status
Not open for further replies.

bwgreen

Programmer
Mar 23, 2006
68
CA
I am looking for a way to change the time zone and DST settings on some computers remotely. We have a number that are incorrectly set, and I don't want to have to visit each machine, if I can help it! All I want to do is set the local TZ to GMT, and turn DST off.

Any ideas?

Thanks,

Brian
 
You can grab time zone information using WMI like this:
Code:
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")

For Each objItem in colItems
    Wscript.Echo "Bias: " & objItem.Bias
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Daylight Bias: " & objItem.DaylightBias
    Wscript.Echo "Daylight Day: " & objItem.DaylightDay
    Wscript.Echo "Daylight Day of Week: " & objItem.DaylightDayOfWeek
    Wscript.Echo "Daylight Hour: " & objItem.DaylightHour
    Wscript.Echo "Daylight Millisecond: " & objItem.DaylightMillisecond
    Wscript.Echo "Daylight Minute: " & objItem.DaylightMinute
    Wscript.Echo "Daylight Month: " & objItem.DaylightMonth
    Wscript.Echo "Daylight Name: " & objItem.DaylightName
    Wscript.Echo "Daylight Second: " & objItem.DaylightSecond
    Wscript.Echo "Daylight Year: " & objItem.DaylightYear
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Standard Bias: " & objItem.StandardBias
    Wscript.Echo "Standard Day: " & objItem.StandardDay
    Wscript.Echo "Standard Day of Week: " & objItem.StandardDayOfWeek
    Wscript.Echo "Standard Hour: " & objItem.StandardHour
    Wscript.Echo "Standard Millisecond: " & objItem.StandardMillisecond
    Wscript.Echo "Standard Minute: " & objItem.StandardMinute
    Wscript.Echo "Standard Month: " & objItem.StandardMonth
    Wscript.Echo "Standard Name: " & objItem.StandardName
    Wscript.Echo "Standard Second: " & objItem.StandardSecond
    Wscript.Echo "Standard Year: " & objItem.StandardYear
    Wscript.Echo
Next

However if you take a look at that class using WBEMTEST of CIMStudio you will see that the class has no methods, so you can't set it.

You might get away with a registry hack or using SendKeys to control the Time applet.

You can call up the applet using the following code:

Code:
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "control timedate.cpl ,1", 1, True

From there you will need to figure out with the keyboard only how to get the time zone you want. Use AppActivate and SendKeys to set the desired value.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark - I'll give it a shot!

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top