none
Can a batch file be written to check status of Wifi adapter? Then as outcome change it to the opposite current setting? RRS feed

  • Question

  • Hi all,

    Is it possible to have a batch file check the status (Enabled/Disabled) of a wireless adapter and as an outcome have it change the adapters setting to the opposite of it's current setting?

    i.e. If set as ENABLED, it will disable it as an outcome.

          If set as DISABLED, it will enable it as an outcome.

    Thanks as this would be extremely useful to overcome a recent problem with Windows 7 not recognising my dads laptop FN key (aeroplane mode).

    Saturday, May 31, 2014 5:30 PM

Answers

  • @echo off
    echo Please wait ... toggling wireless adapter ...
    set "toggle=DISABLE"
    netsh interface show interface name="Wireless Network Connection" | find /i "Disconnected" >nul && set "toggle=ENABLE"
    netsh interface set interface "Wireless Network Connection" %toggle%
    echo Process completed
    timeout /t 10

    Works just as good.
    Sunday, June 1, 2014 4:47 PM
  • Is it possible to have a batch file check the status (Enabled/Disabled) of a wireless adapter?

    Yes, this is possible by using devcon.exe which can be downloaded from here or as part of the Windows Driver Kit.
    Saturday, May 31, 2014 5:38 PM
  • What is the syntax I should use to lookup this connect state value?
    Here you go:
    netsh interface show interface name="Wireless Network Connection" | find /i "connected" && goto Disable
    Sunday, June 1, 2014 2:55 PM

All replies

  • Is it possible to have a batch file check the status (Enabled/Disabled) of a wireless adapter?

    Yes, this is possible by using devcon.exe which can be downloaded from here or as part of the Windows Driver Kit.
    Saturday, May 31, 2014 5:38 PM
  • Hi all,

    I've managed to program 2 batch files (one enables and the other disables):
    ENABLE WIFI =
    @echo off
    echo Please wait ... enabling wireless adapter ...
    netsh interface set interface "Wireless Network Connection" ENABLE
    echo Your wireless network adapter should now be enabled.
    timeout/t 10
    DISABLE WIFI =
    @echo off
    echo Please wait ... disabling wireless adapter ...
    netsh interface set interface "Wireless Network Connection" DISABLE
    echo Your wireless network adapter should now be disabled.
    timeout/t 10
    These both work perfectly on my Windows 7 laptop.  8)

    HOWEVER ... I'd like to code a single batch file which first checks the connect status of the wireless adapter and then through a IF statement sets the opposite outcome to the current status.

    I'm not entirely sure how to code this though.  :oops:

    I know ... netsh interface show interface name="Wireless Network Connection" ... provides the connection status with "Connect State".

    What is the syntax I should use to lookup this connect state value?

    Sunday, June 1, 2014 2:19 PM
  • What is the syntax I should use to lookup this connect state value?
    Here you go:
    netsh interface show interface name="Wireless Network Connection" | find /i "connected" && goto Disable
    Sunday, June 1, 2014 2:55 PM
  • Got it working :)

    @echo off
    echo Please wait ... toggling wireless adapter ...
    netsh interface show interface name="Wireless Network Connection" | find /i "Connected" >nul && set "toggle=DISABLE"
    netsh interface show interface name="Wireless Network Connection" | find /i "Disconnected" >nul && set "toggle=ENABLE"
    netsh interface set interface "Wireless Network Connection" %toggle%
    echo Process completed
    timeout /t 10

    Please correct if I've badly coded this.

    Sunday, June 1, 2014 3:22 PM
  • @echo off
    echo Please wait ... toggling wireless adapter ...
    set "toggle=DISABLE"
    netsh interface show interface name="Wireless Network Connection" | find /i "Disconnected" >nul && set "toggle=ENABLE"
    netsh interface set interface "Wireless Network Connection" %toggle%
    echo Process completed
    timeout /t 10

    Works just as good.
    Sunday, June 1, 2014 4:47 PM
  • The idea in these forums is to mark the one reply as "Answer" that supplies the essential elements to solve your problem. Embedding my suggestions in your own code, then marking your own reply as "Answer" feels rather odd . . .
    Sunday, June 1, 2014 5:26 PM
  • You offered an alternate answer to my original question. I don't see how the answer I have provided is not what I asked for?
    Sunday, June 1, 2014 10:01 PM
  • First question: 'Is this possible?'

    First answer: 'Yes'

    Second question: What is the syntax I should use to lookup this connect state value?

    Second answer: See the post above that I had already proposed as an answer.

    The "answer" you "provided" was guided by those two posts, hence that is why you should at least mark both of those as answers alongside your own.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Sunday, June 1, 2014 10:37 PM
  • Agreed. Apologies. I did not realise we could mark more than one answer :)
    Monday, June 2, 2014 8:45 AM
  • Works a treat, thank you.
    Saturday, September 12, 2015 12:38 AM