20

Is there a way to enable/disable a wireless network interface via the command line (so I can put it in a bat file)?

When I'm in the office I use a wired connection, but Windows still occasionally bugs me about my wireless connection not being connected (even though I turned off the option for notifying me when there's no connectivity). I'm guessing the only way to stop it from bugging me is to disable the interface, but I'd rather not have to go into the network settings every time I need to do so.

I'd like to set up a bat file or a shortcut that I can use to enable/disable the wireless (preferably a single one that toggles the current state), and then just set up a keyboard shortcut for that. I just have no idea how to do so from the command line.

6
  • This only addresses enabling/disabling at the device driver level not the turn on/off of the device itself. I do not want the enable/disable, but the turn on/off. In particular my WiFi defaults off, but when I come to certain customer sites, to do service work, I need a .bat or .wsh script file that turns on the WiFi and connects to the correct profile for that customer and I want to additionally write it to link in the network printers, so I can print my reports, etc.
    – user69892
    Mar 2, 2011 at 20:18
  • @KronoS: Go ahead and just flag for moderator attention on any "answer" that needs to be a comment in the future. We have a convert tool to do it properly. Thanks.
    – Troggy
    Mar 2, 2011 at 20:21
  • @OldManRiver: That sounds like you have an additional question. I would search Super User to see if you can find something that answers question and if not, go ahead and ask a new question.
    – Troggy
    Mar 2, 2011 at 20:25
  • @Troggy I was following these instruction as per @IvoFlipse. Will stop future "conversion" however. :) Mar 2, 2011 at 20:25
  • @KronoS: Thanks for the reference. If it is an "answer" that needs to be part of the OP question, then go ahead and edit the question and add the "answer" portion to it, then flag the "answer" for deletion. For "answers" that need to become comments, go ahead and just flag those ones. We appreciate the help, but this way we can keep all content associated to the correct users.
    – Troggy
    Mar 2, 2011 at 20:30

7 Answers 7

9

I'd like to set up a bat file or a shortcut that I can use to enable/disable the wireless

Use Microsoft DevCon ...

The DevCon utility is a command-line utility that acts as an alternative to Device Manager. Using DevCon, you can enable, disable, restart, update, remove, and query individual devices or groups of devices. DevCon also provides information that is relevant to the driver developer and is not available in Device Manager.

And here's tutorial for you:

Enable/Disable Wireless Card from Command Line

preferably a single one that toggles the current state

You'll need two batch files, one for WiFi Off and one for WiFi On.

Having said that, i assume you're using a laptop. Are you sure your Laptop doesn't allow to toggle WLAN on/off via a Fn key combo or a physical switch? Can you post make and model?

6
  • The laptop has a toggle, but it's only for the antennae, not the device. So Windows still sees the device and complains that it's not connected, even though it can't see any networks.
    – Herms
    Feb 3, 2010 at 21:15
  • @Herms - only for the aerial? that's very unusual. you can also disable the wireless controller from the device manager, expand Network Adapters, right click on the WLAN controller and select disable ... which is exactly what DevCon will do from the command line.
    – Molly7244
    Feb 3, 2010 at 21:20
  • Yea, I know I can disable it through that. I just want to avoid having to do that all the time. Bat file lets me assign a keyboard shortcut to it. I think I have a powershell script that works as a toggle (couldn't figure out the bat for it, then remembered I have powershell installed)
    – Herms
    Feb 3, 2010 at 21:40
  • Might write up a blog post about it at some point, but for now, here's the powershell script I wrote for a toggle: gist.github.com/294059
    – Herms
    Feb 3, 2010 at 21:48
  • 1
    Writeup for how I set everything up: blog.aherrman.com/2010/02/…
    – Herms
    Feb 4, 2010 at 15:39
15

Following works on Win 7 from a cmd prompt with admin privileges:

To Disable:

netsh interface set interface "Wireless Network Connection" Disable

To Enable:

netsh interface set interface "Wireless Network Connection" Enable

To get the interface names:

C:\Users\nirmal>netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        Wireless Network Connection
Disabled       Disconnected   Dedicated        Local Area Connection
2

I made a batch file for switching between LAN and WLAN. It enables your LAN connection and disables your WLAN connection if WLAN is active, and vice versa.

The batch file has been tested on Windows 7. Call it WLAN-LAN.bat and start it as an elevated prompt.

@Echo off

Echo De Netwerkinstellingen worden omgezet van WLan naar LAN of Vice Versa ! 
Echo Even Geduld svp  .................................................

net start dot3svc
netsh lan show interfaces >NUL

if errorlevel 1 goto LAN
if errorlevel 0 goto WLAN

:LAN

netsh interface set interface "Draadloze netwerkverbinding" disabled >NUL

sc start dot3svc >NUL
netsh interface set interface "LAN-verbinding" enabled >NUL

goto end

:WLAN

sc start dot3svc >NUL
netsh interface set interface "LAN-verbinding" disabled >NUL
sc stop dot3svc >NUL

netsh interface set interface "Draadloze netwerkverbinding" enabled >NUL

:end

You should change the names of the network interfaces to match the network interfaces on your own system. So change the names between quotes: "...".

Further, should you set wired autoconfig service on automatic. The text in the comments can be changed as you wish.

3
  • 1
    Could you clarify if anything in the script must be changed for languages other than Dutch? Or better still, translate the comments and string literals to English?
    – sblair
    Sep 9, 2011 at 17:22
  • @sblair just modify string at "", must change Draadloze netwerkverbinding to your interface name like wireless connection..
    – netawater
    Sep 25, 2015 at 6:35
  • 1
    Is it "net start dot3svc" be added wrong? it cause errorlevel be 0 always.
    – netawater
    Sep 25, 2015 at 6:56
2

FYI ... for 64bit version of vista and Win7 the "64bit" version noted above will not work. You have to download the entire windows device driver kit, then extract devcon.exe from here: C:\WinDDK\7600.16385.1\tools\devcon\amd64\devcon.exe and paste into c:\Windows/system23 (I know, I know ... I also have an Intel i3 and still had to use this "amd64" one)

The WinDDK kit can be found here: http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx It's huge (620 MB). The devcon file is tiny. :p

Note: An easy way to find the device driver number for any device by going into device manager (from control panel), look at the properties, and under "details" select "Hardware IDs". There will be a big number, you just want this part: DEV_???? (fill in the ? with your 4 numbers). For example if it's DEV_4315 then put this in enable.bat: devcon enable "*DEV_4315", and put this in disable.bat: devcon disable "*DEV_4315".

Please make sure and add the wildcard preceding it: *DEV_???? (see the 2 examples I just gave). You'll need to run them as administrator. FYI ... if you have a hardware indicator light then this will probably not toggle it.

2

use this bat file for toggle wlan.

@Echo off 

set interface="Wireless Network Connection "
ipconfig | find %interface% >NUL

rem if errorlevel 0 goto LAN
rem if errorlevel 1 goto WLAN
if %errorlevel% EQU 0 goto LAN
if %errorlevel% EQU 1 goto WLAN

:LAN
echo "LAN"
netsh interface set interface %interface% disabled
goto end

:WLAN
echo "WLAN"
netsh interface set interface %interface% enabled

:end
1
  • Not working in Windows 11... "There is no more data available." ("Es sind keine Daten mehr verfügbar.")
    – AxelS
    Nov 26, 2022 at 21:28
0

Another Possibility is Sikuli Script. Sikuli is really cool because it takes a visual approach to scripting, and should easily be able to accomplish what you need. Check out the video at the above link to see what I mean. Sikuli runs on Mac, Windows, and Linux.

1
  • Amusingly, I just discovered that this morning. I don't think I'd want to use that for scripting things like this, as it would generally take a lot longer to run.
    – Herms
    Feb 4, 2010 at 18:24
0

It may be possible using the wmic utility (although I'm not sure if it comes with Windows Vista/7/etc.)

or

(though this is a funny way to do it and may break stuff, and it may not work so well) use the netsh tool (also it might not come with the new Windows versions) to give the network adapter a manually-assigned IP address if it is supposed to have a auto-assigned one, or the other way around.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .