Search code examples
pythonpython-3.xdevice-manager

Check device state from Device Manager in Python


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.


Solution

  • 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