Forum Discussion
Hello Madhi,
Below, is a sample script demonstrating how to change the local time zone:
function Main()
{
// Time zones:
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
var timezone = "Central Europe Standard Time";
setTimeZone(timezone);
}
function setTimeZone(timezone)
{
var WshShell = Sys.OleObject("WScript.Shell");
var cmdLine = "RunDLL32.exe shell32.dll,Control_RunDLL timedate.cpl,,/Z";
var WshShellExec = WshShell.Exec(cmdLine + timezone);
}
Hello Madhi,
Here is the VBScript version of the code:
Sub Main
Dim timezone
' Time zones:
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
timezone = "Central Europe Standard Time"
setTimeZone(timezone)
End Sub
Function setTimeZone(timezone)
Dim WshShell, cmdLine, WshShellExec
Set WshShell = Sys.OleObject("WScript.Shell")
cmdLine = "RunDLL32.exe shell32.dll,Control_RunDLL timedate.cpl,,/Z"
Set WshShellExec = WshShell.Exec(cmdLine + timezone)
End Function- TimoFOccasional Contributor
Hello
I was searching for the same topic (I know this is an old post) and I found another solution which works better for newer OS.
Windows7 and also Windows Server 2008 R2 has the command 'tzutil' which can easily change time zone from windows command line (reference http://www.windows-commandline.com/set-time-zone-from-command-line/).
So the JScript version of the setTimeZone() would be:
function setTimeZone(Timezone) { var WshShell = Sys.OleObject("WScript.Shell"); var CmdLine = "tzutil /s "; var Param = CmdLine + aqString.Quote(Timezone); Log.Message("Parameter: "+ Param); var WshShellExec = WshShell.Exec(Param); }
- MadhiContributoris it possible to change the region as well like different countries...
- MadhiContributor
- MadhiContributorsorry about my message posted on may 7th. Looks like i got mixed up with what i had in mind. I wanted to ask you about vbsript and instead i asked about different countries.
- MadhiContributor
function tz
'// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones'Eastern Time (US & Canada)
timezone = "Eastern Time (US & Canada)"
setTimeZone(timezone)
End functionfunction setTimeZone(timezone)
Set WshShell = CreateObject("WScript.Shell")
cmdLine = "RunDLL32.exe shell32.dll,Control_RunDLL timedate.cpl,,/Z"
WshShellExec = WshShell.Run(cmdLine + timezone)
end function
My function above in vbscript. I get no errors but I dont see the changes effected. - MadhiContributorAlex:
Thank you so much for the code. Until I restart, the changes are not effected in my app. Is it possible to change the settings and restart the machine and continue testing??? - AlexKarasChampion Level 3Hi Madhi,
Have a look at aqEnvironment.RebootAndContinue(), hope it should work for you.
Related Content
- 11 years ago
- 5 years ago
Recent Discussions
- 2 days ago