I need to automate the uninstall and reinstall a driver on Windows 7. The process to manually do this is:
- Start
- Right Click Computer > Manage
- Device Manager > Network Adapters
- Right Click Intel(R) Dual band Wireless-AC 7260 > Uninstall
- DO NOT DELETE, leave the delete option unchecked, just hit OK for it to be uninstalled.
- Right click Network Adapters > Scan for Hardware Changes
I need to regularly perform these steps, so I'd like to find a way of automating them.
I have found these two command line tools which seem relevant, but neither of them seem to do exactly what I want.
wmic
# Outputs a list. I can parse this to find the index of the device.
wmic nic get name, index
wmic path win32_networkadapter where index=<from above> call disable
wmic path win32_networkadapter where index=<from above> call enable
Those commands have output that suggests they did whatever they're supposed to do, but it doesn't have the same effect as uninstalling and reinstalling the driver.
pnputil
pnputil -e
This outputs a list. It doesn't seem to include the same human readable name used in Device Manager (which wmic above did), but I see this device listed which I think is it:
Published name : oem186.inf
Driver package provider : Intel
Class : Network adapters
Driver date and version : 08/01/2013 16.1.3.1
Signer name : Microsoft Windows Hardware Compatibility Publisher
I have a few problems with this, though. When I go into the GUI Device Manager and Right Click Driver > Properties > Driver Tab > Driver Details, it lists off the following files:
C:\windows\system32\DRIVERS\Netwfw02.dat
C:\windows\system32\DRIVERS\NETwsw02.sys
C:\windows\system32\drivers\vwifibus.sys
None of which are the name that pnputil
called it. Further, Details Tab > Included Infs calls it netvwifibus.inf
– also not something pnputil
called it.
Another issue with pnputil
is it doesn't seem to have an uninstall command. All it has is pnputil -d
, which it says is for deleting the package (what is a package? How does that differ from a driver? Are they they same?) My manual instructions are explicitly not to delete the driver, only to uninstall it. I'm hesitant to even try using this delete option since I see no easy way of undoing it if it ends up being the wrong thing.
summary
wmic
can disable and enable drivers, but I want to uninstall and reinstall them.
pnputil
can add and delete packages. The word delete scares me as it seems to offer no way of easily backing up or rolling back, so I haven't tried it. Also, what is a package anyways? What is its relationship with a driver… is it the same thing?
Best Answer
PnP, Packages and drivers
Your device is a PnP (Plug and Play) device - It means that Windows, automatically chooses the driver to use for this device. One place where it looks for drivers is a Driver Store on a local computer. Driver Store contains Driver Packages. Several Packages for one device can be present and one Package can have drivers for multiple devices. When a device have no driver assigned, PnP manager finds compatible drivers, ranks them, chooses best one and installs this driver.
When you download and install driver manually, its copy is placed in Driver Store as package.
When you manually uninstall driver and select delete option in Device Manager - it also removes the corresponding package from Driver Store.
wmic, pnputil
To automate exact steps you mentioned, both
wmic disable
andpnputil -d
is not good for you.pnputil
just adds/removes packages, PnP Manager chooses what to install.You want to uninstall driver (but not delete it's package and force a PnP rescan).
proposed solution
I would try to use Windows Device Console (Devcon.exe). Its
remove
command should remove device from device tree and leave package alone - just like your steps 4 and 5. By usingrescan
you can trigger step 6. You can finddevcon
in Windows Driver Kit.You can also write a program using Public Device Installation Functions