Enable/disable wireless interface in a bat file

Solution 1:

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?

Solution 2:

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

Solution 3:

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.

Solution 4:

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.

Solution 5:

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