OK, so the below script removes the spaces from before and after, and it works now. I am sure there are much better ways to write this.
setlocal enableextensions enabledelayedexpansion
for /f "tokens=1-2 delims=:" %a in ('netsh wlan show interface^|find "Name"') do (echo %b >> c:\temp\WLANINT.txt)
for /f "delims=" %x in (c:\temp\WLANINT.txt) do SET WLANINT=%x
:SpaceX
echo "%WLANINT%"
IF "%WLANINT:~0,1%"==" " (SET WLANINT=%WLANINT:~1,-1%)
echo "%WLANINT%"
IF "%WLANINT:~0,1%"==" " GOTO SpaceX
echo "%WLANINT%"
for /l %a in (1,1,100) do if "!WLANINT:~-1!"==" " set WLANINT=!WLANINT:~0,-1!
echo."%WLANINT%"
netsh wlan set profileorder name="%WIFI%" interface="%WLANINT%" priority=1
echo "%WLANINT%"
Try next code snippet (save as 31194241.bat
; running it might require administrative privileges):
@ECHO OFF >NUL
SETLOCAL enableextensions
for /f "tokens=1,* delims=:" %%a in ('
netsh wlan show interface^|find "Name"
') do for /f "tokens=*" %%x in ("%%b") do (
echo netsh wlan set profileorder name="%WIFI%" interface="%%x" priority=1
)
Changes made to your script ( read more ):
%a
, %b
, %c
doubled percent signs as %%a
, %%b
, %%c
for using in a .bat
script; for /f "tokens=*"
will left trim blak space(s); netsh
command is merely echo
ed for debugging purposes only (replace echo netsh
with netsh
no sooner than debugged). Instead of batch, one could use an one-liner from command line:
for /f "tokens=1,* delims=:" %a in ('netsh wlan show interface^|find "Name"') do @for /f "tokens=*" %x in ("%b") do @echo netsh wlan set profileorder name="%WIFI%" interface="%x" priority=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.