1

I'm trying to disable/enable input devices in my laptop (win10), automatically (.reg file, python code etc) I tried to use DevCon but after a lot of attempts it didn't work out for my touchpad and keyboard (I tried to disable, remove). I searched the web and the solutions don't completely disable the devices (for example: Ctrl+Alt+Delete is not blocked).

I work on a windows 10 Laptop, You can assume that you have admin Privileges.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
MTD
  • 19
  • 3

2 Answers2

0

Have to check for Keyboard but for Mouse and Touchpad, you can use some Powershell commands to check and find out the actual device Classes and InstanceIDs and then turn off with an Admin elevated Powershell prompt.

The InstanceIDs of Mouse and Touchpad is different on different brands and types of Laptops, but first you can identify those with their Classes such as HIDClass. To get that fire up Powershell prompt(you've already tried REG and Python, so assuming you'll be okay with Powershell too (.ps1)) and run this command:

Get-PnpDevice | Where-Object {$_.Class -eq 'HIDClass'}

This may show 2 or 3 entries of which 1 belongs to Mouse and other to Touchpad, this would be a bit of trial and error, you have to pick any InstanceID to make filter more target specific and fire-up admin-elevated Powershell (search Powershell and click on "Run As Administrator") and run Disable-PnpDevice method like below(if InstanceId contains "ACPI"):

Get-PnpDevice | Where-Object {$_.Class -eq 'HIDClass' -and $_.InstanceId -like 'ACPI*'} | Disable-PnpDevice -Confirm:$false

This will disable Touchpad(in mine(Lenovo) it did disabled it) and then you can try out another InstanceID and disable the Mouse too in the same way. Voila !! both are turned off now.

If you prefer this in .ps1 script format then you need a self-elevating script which can enable/disable the devices without any halts, save this code in .ps1 file and then right-click > Run with PowerShell:

 $Loc = Get-Location
 "Security.Principal.Windows" | % { IEX "( [ $_`Principal ] [$_`Identity ]::GetCurrent() ).IsInRole( 'Administrator' )" } | ? {
 $True | % { $Arguments = @('-NoProfile','-ExecutionPolicy Bypass','-NoExit','-File',"`"$($MyInvocation.MyCommand.Path)`"","\`"$Loc\`"");
 Start-Process -FilePath PowerShell.exe -Verb RunAs -ArgumentList $Arguments; } }
 
 Get-PnpDevice | Where-Object {$_.Class -eq 'HIDClass' -and $_.InstanceId -like 'ACPI*'} | Disable-PnpDevice -Confirm:$false
 Read-Host

Note: If you in case disable the wrong or undesired device than for enabling it, in the same admin-elevated Powershell window run the same filter command (the Get-PnpDevice with filters) and replace Disable-PnpDevice with Enable-PnpDevice.

Let me know in comments if you still face issue with above commands.

Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
-1

Untested, but calling BlockInput() should do what you want. It blocks both keyboad and mouse input. It is however defined in user32.dll so you will need to use ctypes to access it:

import ctypes
ctypes.windll.user32.BlockInput(True)
Xantium
  • 11,201
  • 10
  • 62
  • 89
  • @MTD Turns out there is not single command call to bock that. So unless you can find a module to do it, then your best bet is to try and implement this https://stackoverflow.com/questions/4529577/disable-control-alt-delete-and-windowswin-key-in-windows-7-using-win32-app – Xantium Mar 28 '20 at 15:30
  • @MTD This also seems to say you arn't supposed to https://stackoverflow.com/questions/11439317/disable-ctrlaltdel-on-windows-7 May I ask why you want to block input in the first place? It can be annoying for the user to get their input blocked – Xantium Mar 28 '20 at 15:32
  • I'm doing a project in school, I want to allow my users to lock their pc's in case it stealed – MTD Mar 28 '20 at 16:51
  • @mtd: That's utterly useless. If an attacker gains physical access to a device, it's Game Over. The best you can do is to encrypt data on your drive. BitLocker is part of Windows for a considerable time. In other words: The problem you are trying to solve has already been solve, and your proposed solution isn't. – IInspectable Mar 29 '20 at 14:45
  • I don't try to invent the wheel... I defined my targets and this is one of them... – MTD Mar 29 '20 at 23:32
  • @MTD Could going to sleep be an option? https://stackoverflow.com/questions/37009777/how-to-make-a-windows-10-computer-go-to-sleep-with-a-python-script that would force a password. – Xantium Mar 30 '20 at 09:43
  • 1
    @mtd: You cannot solve the problem you stated. A Python script isn't going to intercept the [secure attention sequence](https://learn.microsoft.com/en-us/windows/win32/secgloss/s-gly). Even if that were possible, your proposed solution adds exactly *zero* security. If an attacker gains physical access to your device, they can simply remove the disk, and mount it in a system that doesn't honor the file system security. The system has been compromised the moment the owner lost physical access to it. An encrypted disk is the only way to mitigate a data breach. – IInspectable Mar 30 '20 at 11:47