Can a batch file be written to check status of Wifi adapter?
Moderator: DosItHelp
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Can a batch file be written to check status of Wifi adapter?
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).
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).
Re: Can a batch file be written to check status of Wifi adap
foxidrive wrote:See if you can find a script here:
https://www.google.com.au/search?hl=en& ... apter+wmic
I don't think your Aussie Google Foo is as good as our USA Google Foo!

Re: Can a batch file be written to check status of Wifi adap
hehe Google doesn't give us a choice - you get the au one by default.
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
Hi all,
I've managed to program 2 batch files (one enables and the other disables):
ENABLE WIFI =
DISABLE WIFI =
These both work perfectly on my Windows 7 laptop.
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.
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?
I've managed to program 2 batch files (one enables and the other disables):
ENABLE WIFI =
Code: Select all
@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 =
Code: Select all
@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.

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.

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?
Re: Can a batch file be written to check status of Wifi adap
This should do it...
Code: Select all
@echo off
echo Please wait ... toggling wireless adapter ...
set "toggle=ENABLE"
netsh interface show interface name="Wireless Network Connection" 2>&1 |find /i "Connect state:" | /i find " Connected" >nul && set "toggle=DISABLE"
netsh interface set interface "Wireless Network Connection" %toggle%
echo Process completed
timeout /t 10
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
Hi foxidrive,
Thank you for your reply. The code you provided did not work. I edited it slightly ( see below) but it only disables the wifi (if enabled). If disabled it just stays disabled.
Thank you for your reply. The code you provided did not work. I edited it slightly ( see below) but it only disables the wifi (if enabled). If disabled it just stays disabled.
Code: Select all
@echo off
echo Please wait ... toggling wireless adapter ...
set "toggle=ENABLE"
netsh interface show interface name="Wireless Network Connection" 2>&1 | find /i "Connected" >nul && set "toggle=DISABLE"
netsh interface set interface "Wireless Network Connection" %toggle%
echo Process completed
timeout /t 10
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
Got it working
See below ...
Thanks for all your help as much appreciated

Code: Select all
@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
Thanks for all your help as much appreciated

Re: Can a batch file be written to check status of Wifi adap
I see why my version failed - that's fixed by placing a space in front of " Connected" like so.
Removing the /i case insensitive switch would have fixed it too.
For the same reason your first wmic line will ALWAYS set the variable to DISABLE
and it works because the second wmic line will set it to ENABLE when it's needed.
Using your code, this will also work:
Removing the /i case insensitive switch would have fixed it too.
For the same reason your first wmic line will ALWAYS set the variable to DISABLE

and it works because the second wmic line will set it to ENABLE when it's needed.
Using your code, this will also work:
Code: Select all
@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
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
I'll use your code as it seems more tidier 
Thanks again.

Thanks again.
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
Hi all,
The other day before passing the laptop onto my dad, I enabled UAC (user account control).
Upon demonstrating it to my dad when he came round today to pickup his new laptop; the command prompt window provided the error "An interface with this name is not registered with the router.".
I checked the name of the device and compared it to the device name within the batch file. They were both the same.
I disabled UAC and it worked.
For now I've asked my dad to keep the UAC turned off.
Do you know why this would provide this error? If so is there a way around it? No problem if not as he can cope without UAC turned on.
The other day before passing the laptop onto my dad, I enabled UAC (user account control).
Upon demonstrating it to my dad when he came round today to pickup his new laptop; the command prompt window provided the error "An interface with this name is not registered with the router.".
I checked the name of the device and compared it to the device name within the batch file. They were both the same.
I disabled UAC and it worked.
For now I've asked my dad to keep the UAC turned off.
Do you know why this would provide this error? If so is there a way around it? No problem if not as he can cope without UAC turned on.
-
- Posts: 7
- Joined: 31 May 2014 04:35
- Location: UK
- Contact:
Re: Can a batch file be written to check status of Wifi adap
Found the answer ... sort of.
http://support.microsoft.com/kb/929858c
Is there any "code" which I can use to run the command as the admin account?
http://support.microsoft.com/kb/929858c
Is there any "code" which I can use to run the command as the admin account?
Re: Can a batch file be written to check status of Wifi adap
The usual method is to right click the icon and select run as admin.
-
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
Re: Can a batch file be written to check status of Wifi adap
On Windows 7 or 8 I can just enable or toggle back on my Wi-Fi with this script which will scan all available .xml files
present then reconnect if found.
present then reconnect if found.
Code: Select all
for /f "tokens=*" %%a in ('dir/b/s "%ProgramData%\Microsoft\Wlansvc\Profiles\Interfaces"') do netsh wlan add profile filename="%%a">nul