Enable/Disable a network adapter with a keyboard shortcut
Solution 1
I am going to list the manual steps necessary to quickly enable or disable a network adapter. Then, I will translate these steps into AutoHotkey.
By hand:
-
Open Network Connections from the command line.
explorer ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
-
Once the window is active, press Space to set the focus to the list of adapters.
If the adapter you want to enable/disable is currently selected (i.e. the 1st` on the list), skip to Step #5.
-
If the adapter is not selected, press Right until it is selected. For example press Right 1 time if the adapter is 2nd on the list, 2 times if it is 3rd, etc.
-
Right-click the adapter and press Down to highlight the
Enable
orDisable
option. Press Enter to
Enable
orDisable
.Close Network Connections.
Autohotkey:
Using the keyboard shortcut Ctrl+,
^,::
;1.
Run, explorer ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
;2.
WinWaitActive, Network Connections
Send, {Space}
;3. & 4.
;If the adapter is not the 1st, navigate to it.
;For example, without the comment (semi-colon):
; Send, {Right 1}
;if it is the 2nd adapter.
; Send, {Right 2}
;if it is the 3rd, etc.
;5.
Send, {AppsKey}
Sleep, 250 ;adjust as needed
Send, {Down}
;6.
Send, {Enter}
;7.
WinClose, Network Connections
return
Solution 2
Just go to the screen where the adapter icon is located. Right click and create shortcut (it won't allow to add shortcut to that window but it will allow it to be created in desktop). When you want to enable or disable the adapter just right click the icon on your desktop and click enable or disable.
Solution 3
If you want an easy way to enable or disable your NIC (or other device for that matter), that bypasses the Control Panel, Device Manager, and other windows altogether, you can do so with a a batch file:
Get a copy of Microsoft’s DevCon utility
-
Create and save the following batch file (e.g., as
ToggleNIC.bat
)@echo off if (%1)==(+) goto enable if (%1)==(-) goto disable goto :eof
:: Replace the device ID ("VEN_1234&DEV_5678" in the example) with that of your own NIC. :: You can find it with the command "devcon find PCI*", looking for the name of your NIC.
:: When you locate your device ID, enter only up to the "DEV"; that should be enough to uniquely identify the device. :: Leave the "SUBSYS" and later parts of the string off, otherwise it may not work.
:enable devcon enable "PCI\VEN_1234&DEV_5678" goto :eof
:disable devcon disable "PCI\VEN_1234&DEV_5678" goto :eof Create two shortcuts to the batch file (e.g.,
EnableNIC.lnk
andDisableNIC.lnk
), in one specifying the Target field asC:\…\ToggleNIC.bat +
and for the other,C:\…\ToggleNIC.bat -
(of course replace the…
with the path to the batch file)-
Set a hotkey in the Properties dialog for each shortcut—Ctrl+Alt+Shift+Num+ and Ctrl+Alt+Shift+Num- seem like good, logical ones.
- (There’s a reason Explorer tries to prevent simple shortcuts of the form Ctrl+Key, Alt+Key, and Shift+Key; because those are normally used in programs for everyday tasks, so using them as shell hotkeys would cause no end of trouble. But, if you really need one without Alt, you can manually hack the
.lnk
file or easier, just use a macro/hotkey program to create a task to run the batch files with whatever hotkey you like.)
- (There’s a reason Explorer tries to prevent simple shortcuts of the form Ctrl+Key, Alt+Key, and Shift+Key; because those are normally used in programs for everyday tasks, so using them as shell hotkeys would cause no end of trouble. But, if you really need one without Alt, you can manually hack the
- Alternately, you could put the batch file somewhere in your PATH, then you can simply toggle the NIC via the Start menu or Run dialog; e.g. Win+R,
togglenic +
You can also make it so that the batch file literally toggles the NIC (enable it if it is currently disabled, or disable it if it is currently enabled), but that will be a little more involved and probably not necessary in general.
Related videos on Youtube
Carlos
Updated on September 18, 2022Comments
-
Carlos almost 2 years
I started out trying to use a shortcut to display the Local Area Connection Status window on my desktop by creating a shortcut and assigning it Ctrl+, (comma).
Windows didn't like that, so it added Alt, which ended up being Ctrl+Alt++,.
Since I couldn't figure out a way to eliminate Alt as part of the shortcut keys, I am now trying a different strategy and it's not working. My latest attempt is to use AutoHotkey with the following command:
^,::Run, explorer ::{BA126ADB-2166-11D1-B1D0-00805FC1270E}
Which is what the shortcut target number is, but it won't open the window.
-
iglvzx over 12 yearsI don't understand your question. Can you post your AutoHotkey script? Windows or AutoHotkey should not be sending
[Alt]
every time you press[Ctrl]
, unless you write it that way. -
Carlos over 12 yearsSure, I made a shortcut for the Lan Connection Properties and assigned the following hot keys for it; CTRL + ALT + ,
-
Carlos over 12 yearsDidn't realize that hitting return would finish me off. Anyway, my desire is to have CTRL + , be my hot keys but when you select CTRL as part of your hot keys in Windows, it automatically adds ALT so that I end up with CTRL + ALT + , and I want to do away with ALT and just use CTRL + , - does that explain it better?
-
iglvzx over 12 yearswhere did you get that GUID? It does not open "Local Area Connection"
-
-
Carlos over 12 yearsThank you for responding and I got the message of not posting the same question twice. I'm leaving for a meeting right now but want to clarify something so I'll get back to you a little later. Thanks Carlos
-
Carlos over 12 yearsThe shortcut ended up in the "Programs" folder and I don't know how to insert the command. I thought about doing away with the shortcut idea all together and just go directly tothe program I want to run which is the Local Area Connection so I wrote this script but it doesn't work;
-
Carlos over 12 years;This is to open my Lan Line Connection - not working ^,:: Run, "Control Panel\Network and Internet\Network Connections\Local Area Connection” Return
-
iglvzx over 12 yearsYour code is no good. Paths in the Control Panel are not the same as paths in the filesystem/Windows Explorer. See my updated my answer. :)
-
Carlos over 12 yearsWhat I want to open is the LAN LINE CONNECTION STATUS dialog window so that I can Enable/disable it. I created a shortcut for it, put it on my desktop, went to properties and took down the Target number and created this script but it doesn't work; - ^,:: Run, explorer:: {BA126ADB-2166-11D1-B1D0-00805FC1270E} Return
-
iglvzx over 12 years@Carlos, please edit your original post to include this script. I can't tell if you are adding line breaks or not. This is an important detail. Use the
Code Sample
button on the post editor's toolbar. -
Carlos over 12 yearsWith all the excitement I forgot to assign you any points. Sorry about that, Carlos
-
Carlos over 12 yearsThere is a lot here but I will print it out and review it to see if I can do all of that. For now, if you don't mind, please answer me one question; using Autohotkey, how do I show a command that signifies a double click? I have managed to do everything that I need and I could manually double click it if necessary but if there is a way I could end the script with that, it would be the icing on the cake. Thanks
-
Synetech over 12 yearsI can’t tell what you are asking. You have an AHK script that opens the Network Connections window and emulates key press to navigate to the NIC and toggle it? What’s the double-click for/on? What do you mean by “show a command”?
-
iglvzx over 12 years
-
Carlos over 12 yearsYour script worked fine. I am working on a different script using some of the commands you used on the previous problem and I got it working, All I want to do is end the script with a double click to initiate opening up a window which I am currently doing manually. I'm going to try your suggestion of using the Send, {Enter} and see if that works. If not, i'll try Send {click}.
-
GrahamMc about 11 yearsThought it might be nice to mention you can even go "total keyboard" if you use the keyboard for the "right click" in step 5, using either the "right click" key if your keyboard has one, or "Shift+F10" if your keyboard doesn't have one (e.g. in a VM running on a Mac).
-
Shane about 9 yearsThe "screen where the adapter icon is located" in this case is Network and Internet\Network Connections. Open Network and Sharing Center and then click on "Change adapter settings" in the left pane.
-
stoyanov over 8 yearsIt wasn't working for me at the beginning. I'm on Windows 10. I modified step 6 with another sleep command and then it worked fine. Thanks :)
-
killjoy almost 6 yearsIf there's one thing I have learned on this site and others, dont go by accepted answer or most upvotes, always check last answers coz they are most likely the easiest & best.