Satish Patro
Satish Patro

Reputation: 4404

How to know which SSID I am connected in Windows batch file?

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

Upvotes: 1

Views: 2313

Answers (1)

user7818749
user7818749

Reputation:

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"
)

Upvotes: 1

Related Questions