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

Discussion in 'T&T - Miscellaneous' started by Joe Caverly, Nov 17, 2012.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    488
    Likes Received:
    4
    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
     
    #1
  2. ionamartin123

    Joined:
    Jun 3, 2013
    Messages:
    3
    Likes Received:
    0
    Hi Joe, jus curious(I got a plenty of free time today), does it work with windows 7?
     
    #2
  3. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    450
    Likes Received:
    3
     
    #3
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    488
    Likes Received:
    4
    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
     
    #4
  5. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    488
    Likes Received:
    4
    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
     
    #5
  6. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    488
    Likes Received:
    4
    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
     
    #6
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,531
    Likes Received:
    4
    ... 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.
     
    #7
  8. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    488
    Likes Received:
    4
    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
     
    #8

Share This Page