Enable/Disable a network adapter with a keyboard shortcut

9

4

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.

Carlos

Posted 2012-03-22T14:19:55.627

Reputation: 251

I 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. – iglvzx – 2012-03-22T23:14:11.427

Sure, I made a shortcut for the Lan Connection Properties and assigned the following hot keys for it; CTRL + ALT + , – Carlos – 2012-03-23T00:07:06.273

Didn'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? – Carlos – 2012-03-23T00:12:03.367

where did you get that GUID? It does not open "Local Area Connection" – iglvzx – 2012-03-24T04:58:27.257

Carlos, I don't want to let you down, so I will devise a detailed, easy to follow solution for you. I can't work on it right now, but I should have time tomorrow after 12:00 Pacific. – iglvzx – 2012-03-24T06:44:09.540

Thank you very much. As I said earlier, what you gave me earlier worked just fine but I had not made myself clear. It's not the Network Connection that I want to open. I want to see the Local Area Connection Status window on my desktop so that I can choose to enable/disable it. – Carlos – 2012-03-24T13:33:26.847

Answers

12

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:

  1. Open Network Connections from the command line.

    explorer ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
    

    Network Connections

  2. Once the window is active, press Space to set the focus to the list of adapters.

    list

  3. If the adapter you want to enable/disable is currently selected (i.e. the 1st` on the list), skip to Step #5.

  4. 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.

    2nd

  5. Right-click the adapter and press Down to highlight the Enable or Disable option.

    disable

    enable

  6. Press Enter to Enable or Disable.

  7. 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

iglvzx

Posted 2012-03-22T14:19:55.627

Reputation: 21 611

It 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 :) – Hasan – 2015-11-12T07:46:58.807

Thank 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 – 2012-03-23T14:03:09.983

The 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 – 2012-03-23T21:57:38.650

;This is to open my Lan Line Connection - not working ^,:: Run, "Control Panel\Network and Internet\Network Connections\Local Area Connection” Return – Carlos – 2012-03-23T21:58:49.273

Your 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. :) – iglvzx – 2012-03-23T23:44:59.990

What 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 – Carlos – 2012-03-24T02:52:41.667

@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. – iglvzx – 2012-03-24T02:58:17.780

2The command you gave me opens up the Network Connection as you said but I'm trying to go a step further and open up the LOCAL AREA CONNECTION STATUS window so that I can Enable/Disable the connection. - maybe I didn't make myself clear. I re-wrote the initial question for clarification. Hope that's what you wanted. – Carlos – 2012-03-24T11:08:15.023

iglvzx - YOU ARE OW SOME!!! - It works. I really appreciate the time and effort you put into it. Thanks so much, Carlos – Carlos – 2012-03-24T23:53:16.153

With all the excitement I forgot to assign you any points. Sorry about that, Carlos – Carlos – 2012-03-25T00:16:53.377

Thought 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). – GrahamMc – 2013-06-19T16:30:20.950

6

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.

Frank

Posted 2012-03-22T14:19:55.627

Reputation: 61

1The "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. – Shane – 2015-04-17T05:51:47.817

If 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. – killjoy – 2018-08-02T13:44:14.487

4

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:

  1. Get a copy of Microsoft’s DevCon utility

  2. 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
  3. Create two shortcuts to the batch file (e.g., EnableNIC.lnk and DisableNIC.lnk), in one specifying the Target field as C:\…\ToggleNIC.bat + and for the other, C:\…\ToggleNIC.bat - (of course replace the with the path to the batch file)

  4. 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.)

  5. 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.

Synetech

Posted 2012-03-22T14:19:55.627

Reputation: 63 242

There 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 – Carlos – 2012-03-26T01:31:01.947

I 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”? – Synetech – 2012-03-26T02:27:51.320

@Carlos Did my script not work? If the item you want to double-click has focus (i.e. highlighted blue, or with a dotted box), then you can Send {Enter}. Otherwise, you can use the Click command to simulate a mouse click at a specific location.

– iglvzx – 2012-03-26T03:56:46.543

Your 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}. – Carlos – 2012-03-26T05:59:58.510