Check device state from Device Manager in Python

205 Views Asked by At

I want to check if device is enabled or disabled using python. I want to make a program that would toggle touchscreen on my laptop.

I tried looking for module or cmd command that could do this, but I didn't find any solutions.

1

There are 1 best solutions below

2
Tim Roberts On BEST ANSWER

I have two choices for you.

Everything that Device Manager does is done through the "setupapi.dll" APIs, which all start with SetupDi. Here is a sample module which can iterate through your devices and return their attributes:

https://github.com/gwangyi/pysetupdi

Alternatively, there is a command called "pnputil" that ships with Windows that can enumerate, enable, and disable devices by their hardware IDs.

https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/pnputil-command-syntax