[tools 1/3] testbot/SetWinLocale: Add --sys-copy and --def-copy options.

Francois Gouget fgouget at codeweavers.com
Fri Jan 28 11:31:13 CST 2022


These provide control over copying the new locale to the system and
default user accounts.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/bin/SetWinLocale | 94 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 86 insertions(+), 8 deletions(-)

diff --git a/testbot/bin/SetWinLocale b/testbot/bin/SetWinLocale
index fa5f90cdbb..e544a580d3 100755
--- a/testbot/bin/SetWinLocale
+++ b/testbot/bin/SetWinLocale
@@ -310,7 +310,7 @@ sub CheckLocale($$)
   return undef;
 }
 
-my ($OptHostName, $OptShow, $OptReboot);
+my ($OptHostName, $OptShow, $OptSysCopy, $OptDefCopy, $OptReboot);
 my ($OptDefault, $OptLocale, $OptCountry, $OptSystem, $OptUTF8, $OptMUI, $OptKeyboard);
 while (@ARGV)
 {
@@ -323,6 +323,22 @@ while (@ARGV)
   {
     $OptShow = 1;
   }
+  elsif ($Arg eq "--sys-copy")
+  {
+    $OptSysCopy = 1;
+  }
+  elsif ($Arg eq "--no-sys-copy")
+  {
+    $OptSysCopy = 0;
+  }
+  elsif ($Arg eq "--def-copy")
+  {
+    $OptDefCopy = 1;
+  }
+  elsif ($Arg eq "--no-def-copy")
+  {
+    $OptDefCopy = 0;
+  }
   elsif ($Arg eq "--reboot")
   {
     if (defined $OptReboot and !$OptReboot)
@@ -426,13 +442,32 @@ if (!defined $Usage)
     }
   }
 
-  if (!$OptLocale and !$OptSystem and !$OptMUI and !$OptKeyboard and
-      !$OptCountry and !$OptUTF8 and !$OptShow)
+  if (!$OptLocale and !$OptCountry and !$OptSystem and !$OptUTF8 and
+      !$OptMUI and !$OptKeyboard and !defined $OptSysCopy and
+      !defined $OptDefCopy)
+  {
+    if (!$OptShow)
+    {
+      Error("you must specify at least one locale to change\n");
+      $Usage = 2;
+    }
+    if (defined $OptReboot)
+    {
+      Error("--(no-)reboot can only be used when changing a locale\n");
+      $Usage = 2;
+    }
+  }
+  if ($OptShow and ($OptLocale or $OptCountry or $OptSystem or $OptUTF8 or
+                    $OptMUI or $OptKeyboard or defined $OptSysCopy or
+                    defined $OptDefCopy or defined $OptReboot))
   {
-    Error("you must specify at least one locale to change\n");
+    Error("--show and the locale options are mutually incompatible\n");
     $Usage = 2;
   }
 
+  $OptSysCopy = 1 if (!defined $OptSysCopy);
+  $OptDefCopy = 1 if (!defined $OptDefCopy);
+
   # Two settings only take effect after a reboot:
   # - System locale changes.
   # - Display language changes only require a log out + log in but that cannot
@@ -447,7 +482,7 @@ if (defined $Usage)
     exit $Usage;
   }
   print "Usage: $name0 [options] --show HOSTNAME\n";
-  print "or     $name0 [options] [--default DEF] [--locale LOC] [--country CTY] [--system SYS] [--utf8] [--mui MUI] [--keyboard KBD] [--no-reboot] HOSTNAME\n";
+  print "or     $name0 [options] [--default DEF] [--locale LOC] [--country CTY] [--system SYS] [--utf8] [--mui MUI] [--keyboard KBD] [--no-sys-copy] [--no-def-copy] [--no-reboot] HOSTNAME\n";
   print "\n";
   print "Sets the locale of the specified Windows machine.\n";
   print "\n";
@@ -490,13 +525,32 @@ if (defined $Usage)
   print "                 . Only takes effect after a log out + log in.\n";
   print "                 . Windows 10 GUI: Time & language -> Language -> Windows\n";
   print "                   display language.\n";
-  print "                 . APIs: GetSystemPreferredUILanguages(),\n";
+  print "                 . APIs: GetSystemPreferredUILanguages() (--sys-copy case),\n";
   print "                         GetUserDefaultUILanguage(), GetThreadUILanguage().\n";
   print "                 . Powershell: Set-WinUILanguageOverride -Language MUI\n";
   print "  --keyboard KBD Specifies the keyboard layout (see --defaults).\n";
   print "                 . Windows 10 GUI: Time & language -> Language -> Keyboard ->\n";
   print "                   Override for default input method.\n";
   print "                 . Powershell: Set-WinDefaultInputMethodOverride -InputTip KBD-ID\n";
+  print "  --sys-copy     Copy the current locales (--locale --country --mui --keyboard)\n";
+  print "                 to the system accounts (System/LocalSystem, NT Authority) and\n";
+  print "                 in particular the one used by the logon screen. This is the\n";
+  print "                 default.\n";
+  print "                 . This requires elevated privileges.\n";
+  print "                 . Windows 10 GUI: Time & language -> Language -> Administrative\n";
+  print "                   language settings -> Copy Settings -> Welcome Screen and\n";
+  print "                   system accounts.\n";
+  print "                 . Powershell (Windows 11+): Copy-UserInternationalSettingsToSystem -WelcomeScreen \$True\n";
+  print "                 . Intl.cpl: CopySettingsToSystemAcct='true'\n";
+  print "  --no-sys-copy  Do not copy the current locale to the system accounts such as\n";
+  print "                 the one used by the logon screen.\n";
+  print "  --def-copy     Copy the current locales (--locale --country --mui --keyboard)\n";
+  print "                 to the default user account. This is the default.\n";
+  print "                 . Windows 10 GUI: Time & language -> Language -> Administrative\n";
+  print "                   language settings -> Copy Settings -> New user accounts.\n";
+  print "                 . Powershell (Windows 11+): Copy-UserInternationalSettingsToSystem -NewUser \$True\n";
+  print "                 . Intl.cpl: CopySettingsToDefaultUserAcct='true'\n";
+  print "  --no-def-copy  Do not copy the current locales to the default user account.\n";
   print "  --no-reboot    Do not reboot Windows. Some locale changes only take effect\n";
   print "                 after a reboot so this option should only be used for\n";
   print "                 debugging.\n";
@@ -652,7 +706,7 @@ sub ShowWinSettings($)
   print "OEMCP               (--utf8) = ", Value2Str($Settings->{OEMCP}), "\n";
 
   print "\n";
-  print ".DEFAULT account:\n";
+  print ".DEFAULT account (see --sys-copy):\n";
   # Locale used for the date and time in the logon screen
   print "Locale            (--locale) = ", Value2Str($Settings->{DefLocale}), "\n";
   print "LocaleName        (--locale) = ", Value2Str($Settings->{DefLocaleName}), "\n";
@@ -772,11 +826,13 @@ $OptKeyboard ||= $OptDefault;
 # Generate the intl.cpl configuration
 #
 
+my $CopyToSys = $OptSysCopy ? "true" : "false";
+my $CopyToDef = $OptDefCopy ? "true" : "false";
 my @Config = (
   # intl.cpl does not want single quotes on that one line!
   "<gs:GlobalizationServices xmlns:gs=\"urn:longhornGlobalizationUnattend\">",
   "  <gs:UserList>",
-  "    <gs:User UserID='Current' CopySettingsToDefaultUserAcct='true' CopySettingsToSystemAcct='true'/>",
+  "    <gs:User UserID='Current' CopySettingsToDefaultUserAcct='$CopyToDef' CopySettingsToSystemAcct='$CopyToSys'/>",
   "  </gs:UserList>",
 );
 if (defined $CountryId)
@@ -952,6 +1008,28 @@ if ($KeyboardIds)
   CheckSetting($Settings, "InputMethod", $KeyboardIds->[0], "for --keyboard $OptKeyboard", 1);
 }
 
+if ($OptSysCopy)
+{
+  if ($OptLocale)
+  {
+    CheckSetting($Settings, "DefLocale", "0000$LCIDLocale", "for --locale $OptLocale", 1);
+    CheckSetting($Settings, "DefLocaleName", $OptLocale, "for --locale $OptLocale");
+  }
+  if ($OptCountry)
+  {
+    CheckSetting($Settings, "DefCountry", $CountryId, "for --country $OptCountry");
+    CheckSetting($Settings, "DefCountryName", $OptCountry, "for --country $OptCountry");
+  }
+  if ($OptMUI)
+  {
+    CheckSetting($Settings, "DefMachinePreferredUILanguages", $OptMUI, "for --mui $OptMUI");
+  }
+  if ($KeyboardIds)
+  {
+    CheckSetting($Settings, "DefInputMethod", $KeyboardIds->[0], "for --keyboard $OptKeyboard", 1);
+  }
+}
+
 Cleanup();
 exit(1) if (!$Success);
 Debug(Elapsed($Start), " All done!\n");
-- 
2.30.2




More information about the wine-devel mailing list