Forum Discussion

Madhi's avatar
Madhi
Contributor
15 years ago

Test for Different Regional Settings

One of my scenario involves testing the app in different time settings (Ex. China, NewZealand, France, India, US etc.).  How can I change the system settings through script.  and execute my tests.

9 Replies


  • 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

  • TimoF's avatar
    TimoF
    Occasional 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);
    }
  • is it possible to change the region as well like different countries...
  • sorry 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.

  • function tz

    '// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones'Eastern Time (US & Canada)

    timezone = "Eastern Time (US & Canada)"

    setTimeZone(timezone)

    End function



    function 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.


  • Alex:

    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???
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Madhi,



    Have a look at aqEnvironment.RebootAndContinue(), hope it should work for you.