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

11,760

Solution 1

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:

  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.

Solution 2


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

Share:
11,760

Related videos on Youtube

Robotnik
Author by

Robotnik

[ Software Engineer ] [ Moderator ] [ Volunteer ] [ Gamer ] [ Father ] [ He/Him ] Hello, my name is Ryan, I'm an Elected Moderator on Arqade, the video gaming Stack Exchange site. I'm a full-stack Software Engineer with years of experience in Web and App development. My current tech stack consists primarily of HTML5/JS (React, Typescript), as well as AWS Microservices, Postgres, and a bit of C#. Over the years I've worked with a multitude of technologies: ASP.NET, Android/iOS development, Xbox One and Windows 10 Apps (Both XAML and HTML based ones), Java and so on. I also volunteer in Environment & Sustainability groups in my local area (if you're reading this and into that sort of stuff, you should join the Sustainable Living SE!). I enjoy many video, board and card games, as well as D&D as both DM and player. I'm currently playing in a Star Wars 5e campaign, as a naive Droid Engineer: TA-1! Check it out here: Star Wars D&D. Find me on: YouTube - A Pinch of Salt (Group channel) - game-play and gaming/tech podcasts with friends YouTube - RobotnikPlays - (Personal channel) - game-play, achievements, tricks and techniques, time trials, and commentary on gaming in general. Steam - My primary gaming platform Discord - A Pinch of Salt - Video gaming, D&D, tech and lots more.

Updated on September 18, 2022

Comments

  • Robotnik
    Robotnik over 1 year

    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.

    • and31415
      and31415 almost 10 years
      Windows doesn't provide a way to enable/disable devices from the command-line interface, but you can use the devcon utility. See this related question: Automatically disable integrated webcam when an external one is connected?
    • Robotnik
      Robotnik almost 10 years
      @and31415 - Thanks, this sounds like exactly what I need :). I'll give it a go and report back
    • smali
      smali almost 10 years
      you can also use WMIC commands
  • Fuhrmanator
    Fuhrmanator over 7 years
    Does this work in Windows 10?
  • Robotnik
    Robotnik over 7 years
    @Fuhrmanator no idea, I don't have Windows 10, but I don't see why not.
  • mirh
    mirh over 6 years
    On W10 (and only) you can alternatively use wmic path Win32_PNPEntity where name="whatever" call disable