问题
For now, I have 2 batch file which turns on and off proxy using Registry Editor
Like
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 0 /f
But, I read some where that it is possible to turn on or off proxy based on the network you are connected? So, if I can get the SSID name I can keep this in if else condtion
回答1:
To simply get the SSID
do:
netsh wlan show interface | findstr /i "SSID"
to set the first one as a variable use a for loop (assuming you do not want to use the mac address):
@echo off
for /f "tokens=3" %%i in ('netsh wlan show interface ^| findstr /i "SSID"') do set "myssid=%%i" & goto next
:next
set "myssid=%myssid: =%"
if /i "%myssid%"=="Spektrum" (
reg add ....
)
if /i "%myssid%"=="someotherSSID" (
reg add ....
)
To complete your code as is:
@echo off
for /f "tokens=3" %%i in ('netsh wlan show interface ^| findstr /i "SSID"') do set "myssid=%%i" & goto next
:next
echo %myssid%
set "myssid=%myssid: =%"
echo %myssid%
if /i "%myssid%"=="Spectrum" (
echo "Spectrum"
) ELSE (
echo "Other"
)
来源:https://stackoverflow.com/questions/54860323/how-to-know-which-ssid-i-am-connected-in-windows-batch-file