Enabling and disabling NICs from commandline in Windows
Every so often, someone asks the question: how do I use NETSH to disable a NIC? And the answer is: NETSH cannot disable a NIC.
So here’s how you disable a NIC from the commandline in Windows. The secret is WMIC!
- To see any step, move the video slider to that timestamp.
- You can pause there or watch video.
- Go fullscreen for greater detail; remove captions if they obscure something.
- Still confused? Go here for a better explanation.
- 0:05 Get a list of NICs and their index numbers with the command: wmic nic get name, index
- 0:16 We'll disable the Intel Gigabit NIC, (index number 7). In the upper window, it's presently enabled but disconnected.
- 0:25 The disable command is: wmic path win32_networkadapter where index=7 call disable
- 0:47 Notice that in the upper window, the Gigabit NIC immediately changes to "Disabled"
- 0:55 Re-enabling now with: wmic path win32_networkadapter where index=7 call enable
- 1:02 And we see the NIC enabled again (still disconnected).
- 1:11 That's all, folks!
Netsh can do it.
Netsh can do it, you just need to know the interface name. "Local Area Connection 3" "Corporate" "Home" or whatever. http://www.roelvanlisdonk.nl/?p=1765 and http://forum.sysinternals.com/command-used-to-disable-network-interface_...
netsh interface set interface "<InterfaceName>" ENABLED
or
netsh interface set interface "<InterfaceName>" DISABLED
And for <interfacename> sub your nic's name. Use the quotes, but not the brackets. I've not tried using Netsh to list the adapters, so wmic might be able to get that better. Either way, thanks for the post. Appreciate you putting the info out there.
Cheers -
I have tried this but got an error
Hi all,
i have tried the same command but got the below error. Please help.
C:\>wmic nic get name, index
Index Name
1 Broadcom NetLink (TM) Gigabit Ethernet
2 1394 Net Adapter
3 Microsoft TV/Video Connection
4 RAS Async Adapter
5 WAN Miniport (L2TP)
6 WAN Miniport (PPTP)
7 WAN Miniport (PPPOE)
8 Direct Parallel
9 WAN Miniport (IP)
10 Intel(R) WiFi Link 5100 AGN
11 WAN Miniport (Network Monitor)
C:\>wmic path win32_networkadapter where index=1 call disable
disable - Invalid class method.
C:\>
admin pw creates conundrum
Is there any way for a standard user without an admin password to disable (and then reenable) a network adapter? I'm in the frustrating situation where my standard user must reset his adapter after EVERY reboot before his internet connection will work.. Since this requires admin password, you can probably imagine how annoying it is to have the computer brought to my attention every day (sometimes more than once a day) so I can type the password.
Sorry, can't think of anything.
Honestly, I'd be attacking the root cause of the problem. A NIC should not have to be reset on every reboot in order to work properly.
exactly what I was looking for!
Fantastic; thank you!
this exactly what i wanted!!
THANKS BRO...
we use virtio dirvers. Disabling command returns 740
C:\Users\test_user>wmic nic get name,index
Index Name
0 WAN Miniport (SSTP)
1 WAN Miniport (L2TP)
2 WAN Miniport (PPTP)
3 WAN Miniport (PPPOE)
4 WAN Miniport (IPv6)
5 WAN Miniport (Network Monitor)
6 isatap.ccmp.ibm.lab
7 Red Hat VirtIO Ethernet Adapter
8 WAN Miniport (IP)
9 Red Hat VirtIO Ethernet Adapter #2
10 Teredo Tunneling Pseudo-Interface
11 RAS Async Adapter
12 Red Hat VirtIO Ethernet Adapter #3
We prefer to disable Adapter 2 and 3
so command :
C:\Users\test_user>wmic path win32_networkadapter where index=12 call disable
Executing (\\VM-10-10-165-104\root\cimv2:Win32_NetworkAdapter.DeviceID="12")->dis
able()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 740;
};
returned value 740. We verified that the NICs were not disabled.
Could you help on this one
Admin privs? virtio issue?
First, make sure you run the wmic disable command while elevated to Administrator privs.
If that fails, well ... I have not personally worked with the virtio driver - that's specific to KVM isn't it? Remember, in this case, WMI is just acting as a wrapper to pass commands through to the NIC driver itself. So if the virtio driver doesn't support a disable method, then you'd be out of luck. In which case you might try submitting the issue as a bug to the KVM folks.
Good luck - and if you learn anything new (like, maybe, everything I just said is wrong?) then do please followup here!
we use virtio dirvers. Disabling command returns 740
You were right, it was the administrator priv issue. I executed the commands with privileges and it worked. Thanks.
I used "Macaddress" as the key to disable the NIC instead of "Index" as it suites me better.
wmic nic get name, index,macaddress
Followed by ,
wmic path win32_networkadapter where macaddress="aa:bb:cc:dd:ee:ff" call disable
This work too....
But to enable the same NIC from command prompt , you need to know the "index" value for the corresponding MAC value, else you would be in soup :)
Glad you resolved it
And the query by MAC address is a great idea. Thanks!
command to delete set of NICs in windows 2003 and 2008
Which command can i use to delete set of NICs (one by one) in windows 2003 R2 and 2008 R2 and R1 (32 and 64 bit) .
All i know is the number of NICs present in a VM and the MAC address corresponding to each NIC.