Created
October 1, 2022 14:12
-
-
Save MisaghM/56eeb4d0139a2211341418a5a14a1a2f to your computer and use it in GitHub Desktop.
A simple script to easily enable and disable your system proxy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL EnableExtensions DisableDelayedExpansion | |
REM This script sets and toggles your system proxy. | |
REM (Internet Explorer LAN proxy server) | |
REM Call the script with enable/disable/custom as the first command-line argument: | |
REM proxy.bat enable (use a proxy server for your LAN) | |
REM proxy.bat disable (uncheck use a proxy server for you LAN) | |
REM proxy.bat custom (set proxy server to the 'proxy' variable below) | |
REM Or just run the script to get a choice. | |
SET "proxy=http=127.0.0.1:8080;https=127.0.0.1:8080;ftp=127.0.0.1:8080;socks=127.0.0.1:8080" | |
net session > nul 2>&1 | |
IF ERRORLEVEL 1 ( | |
ECHO Administrative permissions required. | |
GOTO end | |
) | |
SET "regkey=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | |
CALL :echoStatus | |
IF /I "%~1"=="enable" CALL :enable & GOTO end | |
IF /I "%~1"=="disable" CALL :disable & GOTO end | |
IF /I "%~1"=="custom" CALL :custom & GOTO end | |
CHOICE /C EDC /M "[E]nable, [D]isable or set [C]ustom proxy" | |
IF ERRORLEVEL 3 CALL :custom | |
IF ERRORLEVEL 2 CALL :disable | |
IF ERRORLEVEL 1 CALL :enable | |
GOTO end | |
:enable | |
REG ADD "%regkey%" /v ProxyEnable /t REG_DWORD /f /d 1 > nul || EXIT /B | |
ECHO Proxy Enabled. | |
EXIT /B 0 | |
:disable | |
REG ADD "%regkey%" /v ProxyEnable /t REG_DWORD /f /d 0 > nul || EXIT /B | |
ECHO Proxy Disabled. | |
EXIT /B 0 | |
:custom | |
REG ADD "%regkey%" /v ProxyEnable /t REG_DWORD /f /d 1 > nul || EXIT /B | |
REG ADD "%regkey%" /v ProxyServer /t REG_SZ /f /d "%proxy%" > nul || EXIT /B | |
ECHO Custom Proxy Activated. | |
EXIT /B 0 | |
:echoStatus | |
FOR /F "skip=1 tokens=3" %%A IN ('REG QUERY "%regkey%" /v ProxyEnable') DO SET "isEnabled=%%A" | |
REG QUERY "%regkey%" /v ProxyServer > nul 2>&1 | |
IF NOT ERRORLEVEL 1 ( | |
FOR /F "skip=1 tokens=2,*" %%A IN ('REG QUERY "%regkey%" /v ProxyServer') DO SET "currentProxy=%%B" | |
) | |
IF %isEnabled% EQU 1 ( | |
ECHO Proxy: Enabled | |
ECHO Current: %currentProxy% | |
) ELSE ( | |
ECHO Proxy: Disabled | |
) | |
ECHO, | |
EXIT /B 0 | |
:end | |
PAUSE | |
EXIT /B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment