使用powershell设置键盘过滤器 [英] Setting up Keyboard Filter using powershell

查看:162
本文介绍了使用powershell设置键盘过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows Embedded 8.1 Industry Pro,我有一个示例机器,我正在使用它来设置主映像。此设置的一部分是使用键盘过滤器禁用(几乎)键盘上的所有用户输入。使用嵌入式锁定管理器创建
过滤器并将设置导出到powershell脚本相对简单,但是当我运行该脚本时,我收到错误并且未添加自定义过滤器。 仅在尝试时才会出现此错误设置
尚不存在的自定义键或自定义扫描码过滤器。所有预定义的过滤器都按预期工作。

Using Windows Embedded 8.1 Industry Pro, I have an example machine that I am working with to setup a master image. Part of this setup is using the Keyboard Filter to disable (nearly) all user input from the keyboard. It is relatively straightforward to create filters using the Embedded Lockdown Manager and export the settings to a powershell script, but when I run that script I get errors and my custom filters are not added. This error occurs only when trying to set custom key or custom scan-code filters that do not yet exist. All of the pre-defined filters work as expected.

具体来说,执行脚本时会出现以下错误:

Specifically, the following error occurs when executing the script:

Set-WMIInstance:Generic failure 

在C:\ Users \Test \Documents\KeyboardFilter.ps1:124 char:9

+        Set-WMIInstance`

+        ~~~~~~~~~~~~~~~~~~
    + CategoryInfo         :InvalidOperation :( :) [Set-WmiInstance],ManagementException

    + FullyQualifiedErrorId:SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance

并且作为参考,它引用的函数:

and for reference, the function that it refers to:

function Block-CustomKey($Id) {
    <#
    .Synopsis
        Enable a custom defined key combination to be blocked by Keyboard Filter.
    .Description
        This function sets a custom defined key combination to be blocked by Keyboard 
        Filter. If the key combination does not already exist, this function creates a 
        new WEKF_CustomKey instance to represent the custom defined key combination, and sets 
        the key combination to be blocked. Changes take place immediately.
    .Parameter Id
        A string that represents the custom key combination to be blocked. A custom key 
        combination consists of zero or more modifier keys, separated by a plus (+) sign, 
        and a key name. The key combination must use the English names for the keys.
    .Example
        Block-CustomKey "Ctrl+V"
        Block-CustomKey "LCtrl+RAlt+F1"
    #>

    $custom = Get-WMIObject -class WEKF_CustomKey @CommonArgs |
        where {
            $_.Id -eq "$Id"
        };

    if ($custom) {
        # Rule exists.  Just enable it.
        $custom.Enabled = 1;
        $custom.Put() | Out-Null;
        Write-Host "Blocking Custom Filter $Id.";

    } else {
        Set-WMIInstance `
            -class WEKF_CustomKey `
            -argument @{Id="$Id"} `
            @CommonArgs | Out-Null
        
        Write-Host "Added Custom Filter $Id.";
    }
}

这完全由嵌入式锁定管理器中的"导出到PowerShell"选项生成。我没有太多使用PowerShell的经验,所以我没有看到任何直接错误。

This is generated entirely by the 'Export to PowerShell' option in the Embedded Lockdown Manager. I do not have much experience working with PowerShell, so I do not see anything immediately wrong with it.

是否有一些我缺少的设置需要更改才能添加自定义通过脚本过滤?嵌入式功能的其他powershell脚本(手势过滤器,Shell启动器)工作正常。

Is there some setting that I am missing that needs to be changed in order to add custom filters via script? The other powershell scripts for embedded features (Gesture filter, Shell launcher) are working fine.

推荐答案

更多信息;我可以通过直接修改注册表来添加自定义过滤器。使用powershell脚本会更好(因为它是由Lockdown Manager自动生成的)但如果没有简单的答案,我可以使用注册表。
A little more information; I am able to add custom filters by directly modifying the registry. Using a powershell script would be preferable (because it is auto-generated by the Lockdown Manager) but if there is no easy answer I can work with the registry.


这篇关于使用powershell设置键盘过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆