@echo off
CLS
SET "Admin="
color 1f
TITLE WLan Service state - Checking for Admin...
echo.
cd %systemroot%\system32
call :IsAdmin

TITLE Check Wireless Lan Service
cls
color 1F
echo.
echo Checking WLan Service state...
echo.
REM Make sure Wlan Service is enabled. As there has been a 'bug' that can switch off wifi since Vista days!
REM What happens is that wifi is all ok then when you reboot/switch on next time the wifi is no longer connected
REM this little tweak makes sure the service is running. It's not foolproof but it does seems to 'work'.

SET "WLanServiceState=Unknown"
SET "WlanState="
FOR /F "tokens=3 delims=: " %%H in ('SC query "WlanSvc" ^| findstr /I "        STATE" 2^>nul') do SET "WLanServiceState=%%H"

IF /I "%WLanServiceState%" EQU "STOPPED" SET "WlanState=0" & Echo WLan Service was: Stopped.
IF /I "%WLanServiceState%" EQU "Manual" SET "WlanState=0" & echo WLan Service was: Manual.
IF /I "%WLanServiceState%" EQU "Disabled" SET "WlanState=0" & echo WLan Service was: Disabled.
IF /I "%WLanServiceState%" EQU "Running" SET "WlanState=1" & echo WLan Service is: Running.

IF /I "%Admin%"=="1" IF /I "%WlanState%"=="0" (
echo.
echo Attempting to enable WLan service...
echo.
sc config WlanSvc start= auto >NUL 2>&1
TIMEOUT /T 1 /NoBreak >nul
net start wlansvc
TIMEOUT /T 1 /NoBreak >nul
echo.
)

IF /I "%Admin%" NEQ "1" echo. & ECHO Re-run script as Administrator to allow switch on of WLan Service.

echo.
pause
exit

=====================================================================================
:IsAdmin
Reg.exe query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
SET "Admin="
)
Cls

exit /b
