Batch – Switch Proxy Auto-Config URL

This is a batch file I wrote designed for a user in a contracting environment to be able to easily switch between the corporate PAC and their customer’s PAC.  If the current PAC is set to the customer’s (or is blank), it will switch it to the corporate PAC; otherwise it will set the PAC to the customer’s.  Only the two variables at the top need be edited.

For reference, this is the setting in question:
pac

@echo OFF
rem -- Set proxy values in following two lines --
set OUR_COMPANY=http://proxy.example.com:8080/
set THEIR_COMPANY=http://proxy.customer.com:8080/
 
set KEY_NAME="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set VALUE_NAME=AutoConfigURL
 
FOR /F "usebackq skip=1 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO ( 
 set PROXY_VALUE=%%C
)
 
 
@echo Current proxy is %PROXY_VALUE%
 
IF "%PROXY_VALUE%"=="%OUR_COMPANY%" (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "%THEIR_COMPANY%" /f
echo Proxy switched to %THEIR_COMPANY%
) else (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "%OUR_COMPANY%" /f
echo Proxy switched to %OUR_COMPANY%
)
 
pause
Advertisements