• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to? Enable/Disable WiFi from command line

I was looking for a way to enable/disable WiFi on my netbook from TCC.

My searching took me to a Microsoft utility called DevCon, from (http://support.microsoft.com/kb/311272).

I wrote a batch file, WiFi.btm, to enable/disable WiFi on my netbook;

@echo off
if %1 eq on devcon enable "*DEV_001*"
if %1 eq off devcon disable "*DEV_001*"
Note that, according to the KB article, this utility only works on Windows 2000, XP, and Server 2003. I am still using good ole' reliable XP.

Also note that I used DEV_001 because that is what my WiFi device is. Refer to this article, which shows how to use DevCon to determine the ID of your WiFi device.

Devcon can be used for more than just enabling/disabling WiFi, but that is all I need it to do for me for now.

Hi Joe, jus curious(I got a plenty of free time today), does it work with windows 7?
I did some testing, and I found out how to do the same thing using PowerShell;

$wifi = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
This works on my Windows Vista Business, and it should work on Windows 7 also.

Of course, your mileage may vary, especially if you have more than one Wireless Adapter. :)

You can also use TCC to determine if your wireless adapter is enabled or disabled.

wmiquery /A /B root\CIMV2 "select * from Win32_NetworkAdapter" | view
will show you all of your network adapters. In my case, I am looking for my D-Link Wireless Adapter.

Found it. Now, I narrow the query to;

wmiquery /A root\CIMV2 "select * from Win32_NetworkAdapter where Name = 'D-Link DWA-525 Wireless N 150 Desktop Adapter(rev.A2)'"
I now check the value for the NetEnabled property, which will be either True or False. Many ways to do this, but I will use TPIPE;

wmiquery /A root\CIMV2 "select * from Win32_NetworkAdapter where Name = 'D-Link DWA-525 Wireless N 150 Desktop Adapter(rev.A2)'" | tpipe /grep=3,0,0,0,0,0,0,0,"NetEnabled"
If you feel adventurous, you could also use @WMI to set an environment variable with your wireless adapter status.

... or create a plug-in variable _wifi which is the state of the WiFi adapter at the time the variable is expanded (the same way as _ready is determined dynamically); maybe even a command WIFI with optional parameter ON or OFF.
The source code for DEVCON is available from http://code.msdn.microsoft.com/wind...71c/sourcecode?fileId=42722&pathId=1482750064

...so turning this into a plugin should be quite easy for someone fluent in C. Unfortunately, that is not me.

Top Bottom