Automate Driver Uninstall and Reinstall on Windows 7

6,125

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 and pnputil -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 using rescan you can trigger step 6. You can find devcon in Windows Driver Kit.

You can also write a program using Public Device Installation Functions

Share:
6,125

Related videos on Youtube

ArtOfWarfare
Author by

ArtOfWarfare

Updated on September 18, 2022

Comments

  • ArtOfWarfare
    ArtOfWarfare almost 2 years

    I need to automate the uninstall and reinstall a driver on Windows 7. The process to manually do this is:

    1. Start
    2. Right Click Computer > Manage
    3. Device Manager > Network Adapters
    4. Right Click Intel(R) Dual band Wireless-AC 7260 > Uninstall
    5. DO NOT DELETE, leave the delete option unchecked, just hit OK for it to be uninstalled.
    6. 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?

    • Admin
      Admin almost 9 years
      Please explain why you need to uninstall and reinstall drivers regularly. This screams out as a case where you are seeking a solution for the wrong problem.
    • Admin
      Admin almost 9 years
      My laptop regularly loses the ability to see wifi networks. It seems to have something to do with connecting it to Ethernet then disconnecting it. Restarting the computer doesn't fix it. Reinstalling the driver does. The reason I follow that procedure is because it's what the help desk at work told me to do whenever I can't see wifi networks, and the procedure works. I have checked for updates to the driver and none are available. I also can't roll back the driver since no prior version is available.
    • Admin
      Admin almost 9 years
      @ChrisInEdmonton - I suppose if you have a way of fixing the actual problem that would be helpful, but I'm still baffled as to how I would uninstall and reinstall a driver via the command line - surely that's a useful thing that other people would want to know how to do?
    • Admin
      Admin almost 9 years
      The very first thing you should try and do is install the latest driver from vendor site. here is the link downloadcenter.intel.com/product/75439/…
    • Admin
      Admin almost 9 years
      @The_IT_Guy_You_Don't_Like - All of those results are about Bluetooth drivers - this is a wifi issue. Also, I tried updating the driver via the Windows service and it told me it was up to date. Finally, this is a company owned computer connecting to an internal VPN... I'd be concerned with the possibility that they've modified the drivers some how to specifically connect with our VPN. Which is why I'd like to use the automating the directions the help desk gives you to solve my problem.
    • Admin
      Admin almost 9 years
      @ArtOfWarfare, They are not bluetooth drivers.(it is bluetooth technology) Windows update may not always find the latest driver. Also, company helpdesk would always point you to install the drivers either from the company repository or the manufacturer site and very unlikely to ask you run wmic script to disable and re-enable device
    • Admin
      Admin almost 9 years
      @The_IT_Guy_You_Don't_Like - Today I decided to bite the bullet and try that upgrade. I'm now running 18.12.1.2 instead of 16.1.3.1... only time will tell whether the weird issues of it randomly losing the ability to connect to wifi will continue or not.
  • Vylix
    Vylix about 7 years
    Try to put the link on a code tag, using backticks instead of quote to enclose the link. This is a very thorough answer. +1
  • Dorian
    Dorian about 7 years
    @Vylix Thanks, after upvote I have enough reputation :)