Is it possible to toggle disabled/enabled devices from Command Line, simlar to Device Manager?

I like to play Fallout 3 which is very buggy normally, and even more so once I've added some mods. Needless to say, it crashes a lot. I can deal with the crashes, the only problem is when it does my sound card gets caught in an endless loop-style playback.

I can stop the looping audio by toggling the device on and off in Device Manager (Disable/Enable), although it's annoying to have to go into Device Manager all the time. So I'm hoping to semi-automate the process.

Is there a way to toggle a device on and off using a batch script? That way I could just place it on the desktop and run it when my sound card starts looping.


Solution 1:


on win10 you can use wmic. I prefer to use PNPDeviceID in where clause. You can first query for exact value. wmic path Win32_PnPEntity where "PNPDeviceID like '%VEN%'" and when you have it then use:

wmic path Win32_PNPEntity where "PNPDeviceID='yourPNPDeviceIDname'" call disable

I found some very useful information about wmic here

Solution 2:

Thanks to the link provided by and31415, I was able to McGyver a solution, using the Device Console (DevCon) utility.

I've copied the instructions for how to get the tool from this answer:

DevCon is a command-line tool that displays detailed information about devices, and lets you search for and manipulate devices from the command line. DevCon enables, disables, installs, configures, and removes devices on the local computer and displays detailed information about devices on local and remote computers.

  1. Download the appropriate .cab package depending on the operating system:

    • devcon x86 (32-bit)
    • devcon x64 (64-bit)

  2. Open the .cab archive and extract the file named fil[some letters and numbers]. It should be about 80 KB.

  3. Rename it to devcon.exe.

Using this tool, I was able to figure out what the Hardware ID was for my soundcard, and use it to enable and disable the device. Seeing as I simply need to toggle the device, My Batch file simply looks like this:

devcon.exe disable "PCI\VEN_13F6&DEV_8788&SUBSYS_85221043"
devcon.exe enable "PCI\VEN_13F6&DEV_8788&SUBSYS_85221043"

That longish string is the Hardware device ID. To find this, I used DevCon's findall command, piping the output to a text file for easy searching.

devcon.exe findall * > C:\output.txt

Searching for my device name, I copied the string that I needed.


Note: Unfortunately, the batch still requires Administrator Privileges to run, but that's a small issue (and one I may be able to solve at a later stage). But for now, this works for me.