How to change device drivers via command line (Windows)

Background

One of my first projects after moving over to engineering was to update vulnerable audio device and touchpad drivers in the environment. The vendor had an .exe for each driver install, so the process should have been simple. For the touchpad drivers, it was smooth as silk. 10,000 users had no idea it had even happened.

That audio driver, not so much. It wasn’t apparent in testing, but for the majority of machines the driver failed to properly load after the reboot. Nearly every single user in the company was impacted. The manual fix was easy. Go to device manager, remove the device, scan for new devices. Fixed. 100% of the time.

But how to script a solution like this to every user in the environment? Not so easy. Microsoft, in its ultimate wisdom, does not include any utilities to do this quickly and effectively in the Operating System. Perhaps some WMI calls would do the trick, but to make something robust enough to handle the variation in the company, not a route I was ready to go down.

I did figure out a solution, but it wasn’t posted as such on the internet. This is where this solution comes into play.

Solution

Windows Device Console (Devcon.exe). This sweet little tool is part of the Windows Driver Kit (WDK), and gives you the ability to do the same things in the command line as you can in Device Manager.

Download the WDK, and grab the devcon.exe for the OS bitness needed (x86/x64). In my solution I included both versions and wrote a detection function to determine which file to use.

…….. More to come