【问题标题】:How to disable touch screen of laptops using PowerShell script?如何使用 PowerShell 脚本禁用笔记本电脑的触摸屏?
【发布时间】:2021-09-29 03:28:42
【问题描述】:

我的客户正在使用“HP Elitebook 840”触摸​​屏笔记本电脑,最近我们为他们的服务推出了一个网站,不幸的是,按钮上的点击事件在该网站上不起作用。经过长时间的研发,我们意识到这是触摸屏问题,禁用它后鼠标点击事件开始起作用。

更多信息在这里:Click events are not working in Chrome, but event fires when we execute it manually from console

由于有 40 多个用户拥有相同的触摸屏笔记本电脑,我们想运行一个脚本来禁用这些笔记本电脑的触摸功能。我认为网络管理员需要运行 powershell 脚本来执行此操作,但我无法弄清楚如何编写单个脚本来禁用系统的触摸屏

我正在阅读http://www.surfaceforums.net/threads/disable-the-touch-screen-to-use-the-pen.12338/,但由于我是 PowerShell 新手,所以需要更详细的步骤。

【问题讨论】:

  • 你不能用 SendKey 发送 +Q 吗?我没有触摸屏,所以无法测试。

标签: powershell touch


【解决方案1】:

用于禁用/启用笔记本电脑触摸屏的 Powershell 掘金。在华硕 UX 501 上的 Windows 10 中测试。以管理员身份运行。

Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Disable-PnpDevice -Confirm:$false

Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Enable-PnpDevice -Confirm:$false

(Source)

【讨论】:

  • 哇!这只是“开箱即用”。不需要重启,不需要 Devcon,甚至不需要设备 ID,什么都没有!
  • 这应该是公认的答案!在我的联想 Yoga 上运行,只需一秒钟,无需重启!
  • 我一直在 Powershell 脚本中为许多来到我的技术商店的客户使用它。这似乎不再像以前那样完美无瑕了。
【解决方案2】:

在 PowerShell 中使用它:

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Wisp\Touch -Name TouchGate -Value 0 -Type DWord

之后重启机器。

【讨论】:

    【解决方案3】:

    您可以使用以下注册表项来禁用触摸输入(需要重新启动):

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wisp\Touch]
    "TouchGate"=dword:00000000
    

    或使用 PowerShell:

    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Wisp\Touch ompany -Name TouchGate -Value 0 -Type DWord
    

    【讨论】:

      【解决方案4】:

      经过反复试验,我决定对我来说最好的办法是保存两个 .bat 文件来处理这个问题,这样我就可以使用 Launchy 轻松启动它。下面的代码 - 您可能需要根据您的配置为 ExecutionPolicy 添加逻辑,但对我来说是书面的。

      将其复制到记事本中并将其另存为 .bat - 只需将“禁用”切换为“启用”即可,您可以选择任一方向

      @ECHO off
      Powershell.exe -Command "& {Start-Process Powershell.exe -ArgumentList '-Command ""& {Get-PNPDevice | Where-Object FriendlyName -Like ''*touch screen*'' | Disable-PNPDevice -Confirm:$false} ; Get-PNPDevice | Where-Object FriendlyName -Like ''*touch screen*'' ; if ($Host.Name -eq ''ConsoleHost'') {Write-Host ''Press any key to continue...'' ; $Host.UI.RawUI.FlushInputBuffer() ; $Host.UI.RawUI.ReadKey(''""NoEcho,IncludeKeyUp''"") > $null}""' -Verb RunAs}"
      

      【讨论】:

        【解决方案5】:

        我发现了这个问题并看到了答案,这很好。但是,我发现我不希望使用两个不同的脚本来启用/禁用触摸屏。我想把它放在一个下面来切换它的状态,所以我写了这个脚本:

        # To allow script to be executed on double click
        # https://stackoverflow.com/a/30644946/1366368
        
        # To sign script
        # https://adamtheautomator.com/how-to-sign-powershell-script/
        
        # To automatically elevate script to admin privs, I used this code fromn https://superuser.com/a/532109/222708
        param([switch]$Elevated)
        
        function Test-Admin {
            $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
            $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
        }
        
        if ((Test-Admin) -eq $false)  {
            if ($elevated) {
                # tried to elevate, did not work, aborting
            } else {
                # Removed -noexit as it will force the powershell instance to keep running after finishing
                Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
            }
            exit
        }
        
        # If Status of touch screen is Error, then it is off.
        $result = (Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Select -ExpandProperty 'Status')
        if ($result -eq 'Error') {
          Write-Host "Enabling touch screen"
          Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Enable-PnpDevice -Confirm:$false
        } else {
          Write-Host "Disabling touch screen"
          Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Disable-PnpDevice -Confirm:$false
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-09-09
          • 1970-01-01
          • 2021-06-14
          • 1970-01-01
          • 2014-07-08
          • 1970-01-01
          相关资源
          最近更新 更多