Forum Discussion

vlad230's avatar
vlad230
Contributor
13 years ago

Using Symbols

Hi guys,



I'm trying to change my machines regional settings by modifying the registry entries using TC8. Currently I'm trying to change the currency but I'm having a few issues with it.



Basically, I'm opening command prompt and entering a string which changes the registry.



I'm trying to change the currency to the EURO symbol (€, ALT+0128) but the issue is that the value reflected in the regional settings for currency isn't the euro symbol but this symbol: Ç (ALT+128). It seems that by some reason the "0" character is left out somehow and this causes the character to change.



I've encountered the same issue with the POUND symbol (£, ALT+156) but this was resolved by using the character: œ (ALT+0156) which was displayed as the pound symbol in regional settings.



I've also tried to use unicode or hex to define the characters but with no luck.



Do you guys have any ideas on how I could do this?



Here's the code I'm using:





function readCMDoutput(command){

//input: command is a string containing teh command you want to run in cmd.exe

//returns a string containg CMD's output

  var WshShellObj = new ActiveXObject("WScript.Shell");

  var WshShellExecObj = WshShellObj.Exec("cmd.exe");

  //send command and exit

  WshShellExecObj.StdIn.Write(command+"\n exit\n");

  //read all the output

  var out = WshShellExecObj.StdOut.ReadAll();

  Log.Message("CMD output: "+out);

  return out;

}





//sCurrency

  var sCurrency = "€"; //euro symbol

  var regAddQuery ='reg add "HKCU\\Control Panel\\International" /v sCurrency /t REG_SZ /d "'+sCurrency+'" /f';

  readCMDoutput(regAddQuery);

  //re-check if the values are correct

  var regQuery ='"HKCU\\Control Panel\\International" /v sCurrency';

  var command = "reg query "+regQuery

  var checkData = readCMDoutput(command);

  if(aqString.Find(checkData, sCurrency) < 0){

    Log.Warning("sCurrency was NOT set correctly, it should be "+sCurrency+" !");

    ok = false;

  }

  else{ Log.Checkpoint("sCurrency was set correctly to "+sCurrency+".");}





Thanks,

Vlad

3 Replies

  • I forgot to mention that my code passes. So, when I check if the value set by reg add is correct by using reg query, it finds the € symbol (I can also see it in the output) but the regional settings displays Ç.



    Any ideas why is this happening?



    Thanks,

    Vlad
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Vlad,



    I believe, the issue has something to do with code pages and limited Unicode support in the Windows command prompt. For example, if you put the commands to a batch file and run it directly from Windows Explorer, you'll get the same result.

    reg add "HKCU\Control Panel\International" /v sCurrency /t REG_SZ /d € /f

    reg query "HKCU\Control Panel\International" /v sCurrency




    I'd actually recommend using TestComplete's aqEnvironment.SetLocalInfo and aqEnvironment.GetLocaleInfo methods instead to change the regional settings. Your script will be much shorter and easier to understand. :)

    function Test() {

      var WM_SETTINGCHANGE = 0x001A;

      var sCurrency = "€"; //euro symbol



      if (aqEnvironment.SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, sCurrency)) {

        // If no error, notify all running applications about the settings change

        SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_NORMAL, 30000, 0); // 30 sec timeout



        var sCurrencyNew = aqEnvironment.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY);

        if (sCurrencyNew != sCurrency) {

          Log.Warning("The currency symbol was NOT set correctly, it should be " + sCurrency + " !");

        }

        else {

          Log.Checkpoint("The currency symbol was set correctly to " + sCurrency + ".")

        }

      }

      else {

        Log.Error("Could not change the currency symbol.");

      }

    }
  • Hi Helen,



    Sorry for the late reply, I was on vacation.



    Your solution works great! Thanks a lot!



    Best regards,

    Sergiu