How to script removing and rescanning "Ghost NIC" devices in Windows

How to script removing and rescanning "Ghost NIC" devices in Windows

book

Article ID: CTX231027

calendar_today

Updated On:

Description

It's sometimes necessary to run DevMgr in "nonpresent device" mode to remove all nonpresent NIC devices, and sometimes the present NIC too, and then rescan the network to fix problems.  It's possible, using the Microsoft Windows Development Kit tool DEVCON.EXE, to script this operation if you know the device ID(s) you need to remove.


Instructions

Download the Microsoft WDK so you can get a single stand-alone program called devcon.exe.  Start here:

https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit

Jump right to "(2) Install WDK for Windows 10, version 1709".  It's not specific to Windows 10, it covers every Windows build up to W10 1709.  Install that on any machine, and find C:\Program Files (x86)\Windows Kits\10\Tools.  

In the "x64" directory, grab devcon.exe.  That is the only file you need from that distribution for this exercise.

Let's assume we need to remove and recsan all VMware VMXNet3 network devices, and that your copy of DEVCON.EXE is in the folder C:\Windows\Setup\Scripts\NIC_Fix\.  These are VEN_15AD&DEV_07B0, but it should be sufficient to search just for the device ID number.  To remove any present and nonpresent devices whose identifiers contain "dev_07b0", run these two commands:

for /f "delims=:" %x in ('C:\Windows\Setup\Scripts\NIC_Fix\devcon.exe findall *dev_07B0*') do C:\Windows\Setup\Scripts\NIC_Fix\devcon.exe remove "@%x"

C:\Windows\Setup\Scripts\NIC_Fix\devcon.exe rescan

The first command runs "devcon findall *dev_07b0*", which returns every device, present or nonpresent, which contains that string in the registry identifier.  And it then runs "devcon remove" on the identifiers returned, to remove them.  The second command triggers a device rescan/reinstall.

If you want to put those in a script instead of running them manually, change each %x to %%x.  If it works from a CMD prompt, it's possible to set it up as a script to run on every boot, or any other circumstance where you might need to do this.

Environment

Citrix is not responsible for and does not endorse or accept any responsibility for the contents or your use of these third party Web sites. Citrix is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement by Citrix of the linked Web site. It is your responsibility to take precautions to ensure that whatever Web site you use is free of viruses or other harmful items.