如何更改其他用户的默认键盘

如何更改其他用户的默认键盘

我工作的地方有 150 多个工作站使用 Windows 7。
这些电脑的默认键盘设置为德语。
很快这些工作站上就会-扫描出一个新字符,德语键盘会读取这个字符,ß
所以我正在寻找最简单的方法将每个键盘的默认键盘设置为英语。

工作站上的用户访问权限非常有限。我们只能使用具有管理员权限的工具进行更改。该工具以管理员帐户运行,我们可以从中访问几乎任何我们想要的内容。

我到目前为止尝试过的:

  1. 命令行 + xml 脚本这里在超级用户上。
    问题是它会更改管理员帐户的默认键盘,因为该工具以管理员帐户运行。我也尝试以本地用户身份运行它,但由于限制,它无法运行。

  2. 我发现的另一个选项是修改注册表
    HKEY_USERS\.DEFAULT\Keyboard Layout\Preload并设置100000409
    问题在于,reg由于限制,我无法以当前用户身份运行文件,而作为管理员用户,它将把此文件应用于管理员帐户。我无法识别其他用户,因为它们显示为示例,S-1-5-21-2013013795-1015563843-1545874412-206927此代码在不同的工作站上发生变化。我无法使用加载配置单元,因为它说它当前正在使用中。

有没有其他方法可以尝试或解决上述解决方案之一以使其发挥作用?以
某种方式将这些解决方案应用于每个用户也是一个很好的解决方案。

编辑:

我不知道这是否有帮助,但有一件事很常见HKEY_USERS:我们需要更改的账户名称总是以 [...] 结尾-1003或者 [...]-1004

答案1

这里有 2 个选项:1. 用于psgetsid.exe识别您在 HKEY_USERS 中看到的用户名和用户 SID 的对应关系,然后在批处理脚本中使用它。在同一批处理中,您可以使用它psexec.exe在远程计算机上执行所需的注册表更改。您可以将包含计算机列表的文本文件传递给这些程序。

Usage: psgetsid [\\computer[,computer2[,...] | @file] [-u Username [-p Password]]] [account | SID]
     -u         Specifies optional user name for login to
                remote computer.
     -p         Specifies optional password for user name. If you omit this
                you will be prompted to enter a hidden password.
     account    PsGetSid will report the SID for the specified user account
                rather than the computer.
     SID        PsGetSid will report the account for the specified SID.
     computer   Direct PsGetSid to perform the command on the remote
                computer or computers specified. If you omit the computer
                name PsGetSid runs the command on the local system,
                and if you specify a wildcard (\\*), PsGetSid runs the
                command on all computers in the current domain.
     @file      PsGetSid will execute the command on each of the computers listed in the file.

2. 第二种选择是在远程计算机上执行此 Powershell 脚本:

New-PSDrive HKU Registry HKEY_USERS
$allusers = Get-ChildItem -Path hku:\ | select -ExpandProperty name
foreach($i in $allusers)
{
    if (($i -like '*S-1-5-21*') -and ($i -notlike '*_Classes*')) {
        "Users found:"
        $i
        Set-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::$i\Keyboard Layout\Preload" -Name 1 -Value 409
        Set-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::$i\Keyboard Layout\Preload" -Name 2 -Value 407
    }
}

它将扫描 HKEY_USERS 中所有可用的 SID,如果它们符合过滤器,则将设置应用于每个 SID。

PS 所有 AD 用户 SID 都以 S-1-5-21 开头,这就是我在过滤器中使用它的原因。最后我还忽略了所有带有 _Classes 的配置单元。

答案2

有很多可用的选项:

  • 您可以使用选项 -executionpolicybypass 启动 powershell.exe。这样您就不必在每台机器上设置执行策略。例如:powershell.exe -executionpolicybypass
  • 您可以使用 PowerShell 远程连接每个工作站并远程运行脚本。无需 psexec。当然,您需要在所有客户端上启用 PowerShell 远程连接。
  • 您可以使用远程注册表连接到所有计算机上的注册表并直接更改设置。这是迄今为止最好的选择。我编写了一个 PowerShell 函数,您可以使用:
函数设置默认键盘
{
    [CmdletBinding()]
    参数
        # 计算机名称
        [参数(强制=$true,
                   管道属性名称值=$true,
                   位置=0)]
        [别名')]
        [细绳[]]
        $ComputerName,

        [参数(强制=$true,
                   位置=1)]
        [细绳[]]
        $布局代码

    过程
    {
        foreach ($Computer 在 $ComputerName 中) {

            Write-Verbose“测试与‘$Computer’的连接……”
            如果(测试连接 $Computer -Quiet -Count 1){

                Write-Verbose‘计算机似乎在线。’
                $State = '在线'

                #连接远程注册中心
                尝试 {
                    Write-Verbose‘正在连接远程注册表……’
                    $oReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('用户',$Computer)
                }
                抓住 {
                    [pscustomobject]@{
                        计算机名称 = $Computer
                        结果 =‘连接失败。’
                    }
                    继续
                }
                Write-Verbose‘连接已建立。’
                $AllUsers = $oReg.GetSubKeyNames() | ?{$_ -类似 '*S-1-5-21*' -并且 $_ -不像 '*_Classes*'}
                foreach ($User 中的 $AllUsers)
                {
                    尝试
                    {
                        $KeyBoards = $oReg.OpenSubKey("$用户\键盘布局\预加载",$true)
                        $i = 1
                        foreach ($Code 在 $LayoutCode 中)
                        {
                            $FullCode = $Code.PadLeft(8,'0')
                            $KeyBoards.SetValue($i,$FullCode,[Microsoft.Win32.RegistryValueKind]::String)
                            $i++
                        }
                        [pscustomobject]@{
                            计算机名称 = $Computer
                            结果 = ‘OK’
                        }
                    }
                    抓住
                    {
                        [pscustomobject]@{
                            计算机名称 = $Computer
                            结果 =‘无法设置值。’
                        }
                    }
                }
            }
            别的
            {
                [pscustomobject]@{
                    计算机名称 = $Computer
                    结果 = ‘计算机处于离线状态’
                }
                继续
            }
        }
    }
}

您可以像这样使用该函数:

\> 设置默认键盘-计算机名 PC1、PC2、PC3 -布局代码 409

\> 获取 ADComputer -Filter * | 设置默认键盘 -LayoutCode 409,407

相关内容