Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Enable/Disable WiFi from command line

Aug
1,917
68
Hi,
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;

Code:
@setlocal
@echo off
if %1 eq on devcon enable "*DEV_001*"
if %1 eq off devcon disable "*DEV_001*"
endlocal

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.

Joe
 
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.
 
Hi Joe, jus curious(I got a plenty of free time today), does it work with windows 7?

As was quoted by JohnQSmith, the article says it does not, however....

I do not have a Windows 7 system to test it on, but I did try it on my Windows Vista Business, and it worked with no problems.

Joe
 
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;

Code:
$wifi = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
$wifi.Disable()
$wifi.Enable()

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

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

Code:
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;

Code:
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;

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

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

Joe
 
Back
Top