【问题标题】:How to use Powershell to customize "Region and Language" settings in win7 or win2008win7或win2008如何使用Powershell自定义“区域和语言”设置
【发布时间】:2012-04-01 23:01:17
【问题描述】:

我是 Powershell 新手,在网上搜索了一整天,但仍然找不到如何在 win7 或 win2008 中使用 Powershell 自定义“区域和语言”设置。

我想在 Powershell 中更改以下设置:

  1. 当前系统区域设置

  2. 短日期和长日期格式

  3. 短时间和长时间格式

  4. 当前位置

有人知道如何使用 Powershell 来做到这一点吗?也欢迎使用 Cmd/Bat/.NET 解决方案!

【问题讨论】:

    标签: .net windows-7 powershell command-line windows-server-2008-r2


    【解决方案1】:

    我知道您的问题是关于 Windows 7;此信息可能对现在运行较新版本的用户有所帮助。 Windows 8 及更高版本中的Set-WinUserLanguageList、New-WinUserLanguageList 和Get-WinUserLanguageList 可让您控制已安装的语言。例如添加语言:

    $list = Get-WinUserLanguageList
    $list.Add("fr-FR")
    Set-WinUserLanguageList $list
    

    PowerShell 3 中的Set-Culture 允许您更改文化,例如为德国选择默认值:

    Set-Culture de-DE
    

    或者,设置自定义格式:

    $culture = Get-Culture
    $culture.DateTimeFormat.ShortDatePattern = 'yyyy-MM-dd'
    $culture.DateTimeFormat.LongDatePattern = 'dddd, d MMMM yyyy'
    $culture.DateTimeFormat.ShortTimePattern = 'h:mm tt'
    $culture.DateTimeFormat.LongTimePattern = 'h:mm:ss tt'
    Set-Culture $culture
    

    要更改位置,请使用Set-WinHomeLocation,例如将用户的位置设置为奥地利:

    Set-WinHomeLocation -GeoId 14
    

    MSDN 有一个list of GeoIds,TechNet 有一个international settings cmdlets 的引用。

    【讨论】:

      【解决方案2】:

      @bourne 带我去

      & $env:SystemRoot\System32\control.exe "intl.cpl,,/f:`"c:\setKeyboardUK.xml`""
      

      注意 , 和 /f 之间没有空格,在整个过程中使用引号和反引号来转义路径周围的引号(这是必要的)。

      这是我的 setKeyboardUK.xml 文件

      <gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"> 
      <!--User List-->
      <gs:UserList>
          <gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/> 
      </gs:UserList>
      <gs:UserLocale> 
          <gs:Locale Name="en-GB" SetAsCurrent="true"/> 
      </gs:UserLocale>
      <!--location--> 
      <gs:LocationPreferences> 
          <gs:GeoID Value="242"/> 
      </gs:LocationPreferences>
      <gs:InputPreferences>
          <!--en-GB--> 
          <gs:InputLanguageID Action="add" ID="0809:00000809" Default="true"/> 
      </gs:InputPreferences>
      

      要检查设置是否已应用(因为失败是无声的)打开事件查看器和“应用程序和服务日志”,然后“Microsoft”、“Windows”、“International”、“Operational”任何成功的更改或失败都会在此处记录(默认情况下启用日志记录)。

      仅供参考,我在 Windows 2008 R2 64 位的 Powershell 3 上完成了所有这些操作。 YMMV

      【讨论】:

      • 为我工作。我发现的实现有一点警告,如果您以管理员身份运行,它将更改默认值(对于新用户)但不会更改现有用户。如果您以非管理员用户身份运行,它将为该用户更改,但不会更改为默认用户。请在实施时牢记这一点。
      【解决方案3】:

      嘿,我知道这有点老了,但我必须这样做,但我是在批处理脚本中完成的。 我现在正试图弄清楚如何在 powershell 中做到这一点。

      在这里查看我的帖子 - https://superuser.com/questions/353752/windows-7-change-region-and-language-settings-using-a-script

      使用以下命令在 Powershell 中也应如此:

      PS C:\> & $env:SystemRoot\System32\control.exe "intl.cpl,, /f:path\to\xml\file\change_system_region_to_US.xml"
      

      但是,对我来说,由于某种原因它不起作用,即使 命令执行没有错误,更改实际上并没有生效。

      如果您从标准 CMD 窗口运行相同的命令,更改会立即生效。 如果你远程引用以匹配你在 CMD 窗口中运行它的方式,你会得到 以下错误:

      PS C:\> & $env:SystemRoot\System32\control.exe intl.cpl,, /f:"path\to\xml\file\change_system_region_to_US.xml"
          Missing argument in parameter list.
          At line:1 char:50
          + & $env:SystemRoot\System32\control.exe intl.cpl,, <<<<  /f:"path\to\xml\file\change_system_region_to_US.xml"
              + CategoryInfo          : InvalidOperation: (,:String) [], RuntimeException
              + FullyQualifiedErrorId : MissingArgument
      

      Powershell 似乎不太喜欢逗号。

      在 .bat 文件中这样做虽然效果很好。只要确保你得到你的国家代码和东西是正确的。获取 .xml 文件以更改所需的参数可能需要进行一些修改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-10
        • 2017-06-17
        • 1970-01-01
        • 1970-01-01
        • 2012-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多