Skip to main content

How to Get the Current Proxy Settings in Batch Script

In corporate network environments, internet traffic is often routed through a proxy server. When a Batch script fails to download an update or connect to a remote server, the culprit is frequently a missing or incorrect proxy configuration. Knowing how to programmatically retrieve these settings is essential for troubleshooting connectivity issues and ensuring your automation works within enterprise security boundaries.

This guide will explain how to extract proxy settings from the Windows Registry, the WinHTTP subsystem, and environment variables using Batch.

Method 1: Querying the Registry (User-Level Proxy)

Most web browsers (like Chrome and Edge) and standard applications use the user's Internet Settings stored in the registry. The registry key path, value names (ProxyEnable, ProxyServer, AutoConfigURL, ProxyOverride), and data formats are language-independent, they are the same on every Windows display language.

@echo off
setlocal enabledelayedexpansion

set "RegKey=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

echo --- USER INTERNET PROXY SETTINGS ---
echo.

rem --- Check if proxy is enabled ---
rem --- ProxyEnable is a REG_DWORD: 0x1 = enabled, 0x0 = disabled ---
set "ProxyEnabled="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyEnable" 2^>nul ^| findstr /i "ProxyEnable"'
) do (
set "ProxyEnabled=%%c"
)

if not defined ProxyEnabled (
echo [WARN] Could not read ProxyEnable from registry.
echo [INFO] The key may not exist on this system.
goto :CheckAuto
)

rem --- Get the proxy server address ---
set "ProxyAddr="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyServer" 2^>nul ^| findstr /i "ProxyServer"'
) do (
set "ProxyAddr=%%c"
)

rem --- Get the proxy bypass/override list ---
set "ProxyBypass="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyOverride" 2^>nul ^| findstr /i "ProxyOverride"'
) do (
set "ProxyBypass=%%c"
)

if "!ProxyEnabled!"=="0x1" (
echo Proxy Status^: ENABLED
echo.

if defined ProxyAddr (
echo Proxy Server^: !ProxyAddr!
) else (
echo Proxy Server^: [Not set]
)

if defined ProxyBypass (
echo Bypass List^: !ProxyBypass!
) else (
echo Bypass List^: [None configured]
)
) else (
echo Proxy Status: DISABLED ^(Direct Connection^)
)

:CheckAuto
echo.

rem --- Check for Auto-Configuration Script (PAC file) ---
set "AutoConfigURL="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "AutoConfigURL" 2^>nul ^| findstr /i "AutoConfigURL"'
) do (
set "AutoConfigURL=%%c"
)

if defined AutoConfigURL (
echo Auto-Config Script (PAC^)^: !AutoConfigURL!
) else (
echo Auto-Config Script (PAC^)^: [None configured]
)

rem --- Check for WPAD Auto-Detect ---
set "AutoDetect="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%\Connections" /v "DefaultConnectionSettings" 2^>nul'
) do (
rem --- Auto-detect is embedded in binary data; simplified check ---
set "AutoDetect=Check Windows Settings > Network > Proxy > Auto-detect"
)

if defined AutoDetect (
echo WPAD Auto-Detect: !AutoDetect!
)

echo.

endlocal
pause

How the registry parsing works:

  1. reg query outputs lines in the format: ValueName REG_TYPE Data. The exact spacing varies between Windows versions.
  2. findstr /i "ProxyEnable" isolates the specific value line, filtering out header lines that reg query may include.
  3. tokens=1,2,* assigns: %%a = value name, %%b = registry type (e.g., REG_DWORD, REG_SZ), %%c = the actual data. The * in position 3 captures everything remaining, which is essential because proxy addresses can contain colons, semicolons, and other special characters.
tip

Registry value names like ProxyEnable, ProxyServer, ProxyOverride, and AutoConfigURL are never translated. They are internal identifiers that remain the same regardless of the Windows display language. This makes registry-based proxy detection inherently multilanguage-safe.

Method 2: Using NETSH (System-Level WinHTTP Proxy)

Windows background services (like Windows Update, BITS, and .NET applications) do not use the user-level registry settings from Method 1. Instead, they use the WinHTTP proxy settings, which are managed separately through the netsh command. This is a common source of confusion, a user's browser can work fine through a proxy while system services fail because WinHTTP has no proxy configured.

@echo off
setlocal

echo --- SYSTEM WINHTTP PROXY SETTINGS ---
echo.

rem --- netsh winhttp show proxy displays the system-level proxy ---
rem --- The command and its output structure are language-independent ---
netsh winhttp show proxy

echo.
echo [INFO] These settings affect Windows Update, BITS, and .NET services.
echo [INFO] They are separate from the browser/user proxy (Method 1).

endlocal
pause

Extracting WinHTTP Proxy into a Variable

If you need the WinHTTP proxy value in a variable for conditional logic, you can parse the netsh output. The proxy address line contains :// or a port number pattern, which provides a language-independent match.

@echo off
setlocal enabledelayedexpansion

set "WinHttpProxy="

rem --- Parse netsh output for a line containing a proxy address ---
rem --- The proxy value contains either "://" or "host:port" format ---
rem --- Direct access shows no such pattern ---
for /f "tokens=1,* delims=:" %%a in (
'netsh winhttp show proxy 2^>nul ^| findstr /r "[0-9][0-9]*\.[0-9]"'
) do (
if not defined WinHttpProxy (
set "WinHttpProxy=%%b"
if defined WinHttpProxy set "WinHttpProxy=!WinHttpProxy:~1!"
)
)

if defined WinHttpProxy (
echo [INFO] WinHTTP Proxy^: !WinHttpProxy!
) else (
echo [INFO] WinHTTP^: Direct access ^(no proxy configured^).
)

endlocal
pause

Method 3: Checking Environment Variables

Some command-line tools (curl, wget, git, npm, pip) look for standardized environment variables rather than Windows internal settings. These variables follow a Unix convention and are increasingly common in cross-platform development workflows.

@echo off
setlocal

echo --- ENVIRONMENT VARIABLE PROXY SETTINGS ---
echo.

set "FoundAny=0"

if defined HTTP_PROXY (
echo HTTP_PROXY: %HTTP_PROXY%
set "FoundAny=1"
)

if defined HTTPS_PROXY (
echo HTTPS_PROXY: %HTTPS_PROXY%
set "FoundAny=1"
)

if defined FTP_PROXY (
echo FTP_PROXY: %FTP_PROXY%
set "FoundAny=1"
)

if defined NO_PROXY (
echo NO_PROXY: %NO_PROXY%
set "FoundAny=1"
)

rem --- Some tools also check lowercase versions ---
if defined http_proxy (
echo http_proxy: %http_proxy%
set "FoundAny=1"
)

if defined https_proxy (
echo https_proxy: %https_proxy%
set "FoundAny=1"
)

if "%FoundAny%"=="0" (
echo [INFO] No proxy environment variables are set.
echo [INFO] Tools like curl, git, and npm will not use a proxy
echo unless configured through their own config files.
)

endlocal
pause

Method 4: Complete Proxy Audit

This script combines all three methods into a single diagnostic report, giving you a complete picture of how traffic is being routed on the machine.

@echo off
setlocal enabledelayedexpansion

echo ============================================
echo COMPLETE PROXY CONFIGURATION AUDIT
echo Computer: %COMPUTERNAME%
echo User: %USERNAME%
echo Date: %date% %time%
echo ============================================
echo.

set "RegKey=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

rem =============================================
rem Section 1: User-Level Proxy (Registry)
rem =============================================
echo [1] USER-LEVEL PROXY (Browser/Applications)
echo --------------------------------------------

set "ProxyEnabled="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyEnable" 2^>nul ^| findstr /i "ProxyEnable"'
) do set "ProxyEnabled=%%c"

if "!ProxyEnabled!"=="0x1" (
echo Status: ENABLED

set "ProxyAddr="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyServer" 2^>nul ^| findstr /i "ProxyServer"'
) do set "ProxyAddr=%%c"

if defined ProxyAddr (echo Server: !ProxyAddr!) else (echo Server: [Not set])

set "ProxyBypass="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "ProxyOverride" 2^>nul ^| findstr /i "ProxyOverride"'
) do set "ProxyBypass=%%c"

if defined ProxyBypass (echo Bypass: !ProxyBypass!) else (echo Bypass: [None])
) else (
echo Status: DISABLED (Direct Connection)
)

set "AutoConfig="
for /f "tokens=1,2,*" %%a in (
'reg query "%RegKey%" /v "AutoConfigURL" 2^>nul ^| findstr /i "AutoConfigURL"'
) do set "AutoConfig=%%c"

if defined AutoConfig (echo PAC URL: !AutoConfig!) else (echo PAC URL: [None])

echo.

rem =============================================
rem Section 2: System-Level Proxy (WinHTTP)
rem =============================================
echo [2] SYSTEM-LEVEL PROXY (WinHTTP / Services)
echo --------------------------------------------

rem --- Capture netsh output line by line ---
set "WinHttpFound=0"
for /f "tokens=*" %%a in ('netsh winhttp show proxy 2^>nul') do (
echo %%a
set "WinHttpFound=1"
)

if "!WinHttpFound!"=="0" (
echo [ERROR] Could not query WinHTTP settings.
)

echo.

rem =============================================
rem Section 3: Environment Variables
rem =============================================
echo [3] ENVIRONMENT VARIABLES
echo --------------------------------------------

set "EnvFound=0"
for %%v in (HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY http_proxy https_proxy) do (
if defined %%v (
call echo %%v: %%%%v%%
set "EnvFound=1"
)
)

if "!EnvFound!"=="0" (
echo [None set]
)

echo.
echo ============================================
echo AUDIT COMPLETE
echo ============================================

endlocal
pause

Why These Settings Vary

Understanding which proxy source applies to which application is critical for troubleshooting:

Proxy SourceUsed By
Registry (HKCU\...\Internet Settings)Browsers (Chrome, Edge, IE), most desktop applications
WinHTTP (netsh winhttp)Windows Update, BITS, .NET services, background tasks
Environment variables (HTTP_PROXY, etc.)Command-line tools: curl, git, npm, pip, wget
WPAD / PAC file (AutoConfigURL)Automatic per-URL proxy routing (used by browsers and some services)

A machine can have different proxy settings at each level. A browser might work fine (registry proxy set) while curl fails (no environment variable) and Windows Update times out (WinHTTP not configured).

How to Avoid Common Errors

Wrong Way: Assuming User Settings Apply to System Services

Settings in HKCU (HKEY_CURRENT_USER) only apply to the currently logged-in user's applications. Windows services, Scheduled Tasks running as SYSTEM, and background update processes use WinHTTP instead.

rem *** BAD: this only checks user-level proxy ***
reg query "HKCU\...\Internet Settings" /v ProxyServer
rem *** "Why can't Windows Update find the server?!" ***

Correct Way: Check both the registry (Method 1) and WinHTTP (Method 2). If they disagree, you have found your problem.

Wrong Way: Using tokens=3 for Registry Values

The reg query output format varies between Windows versions. Some versions add extra spaces or columns. Using a fixed token position like tokens=3 may capture the registry type (REG_SZ) instead of the data.

rem *** BAD: fragile token position ***
for /f "tokens=3" %%a in ('reg query ... /v "ProxyServer"') do set "Proxy=%%a"

Correct Way: Use tokens=1,2,* and filter the output with findstr to isolate the correct line. The * token captures everything after the second column, including values with spaces or special characters.

Wrong Way: Forgetting About PAC Files and WPAD

If ProxyEnable is 0x0 and ProxyServer is empty, many administrators conclude "no proxy is configured." But the network may still route traffic through a proxy via a PAC file (AutoConfigURL) or WPAD auto-detection.

Correct Way: Always check AutoConfigURL in addition to ProxyServer. If a PAC file URL is configured, the proxy is determined dynamically per URL, it cannot be represented as a simple host:port value.

Problem: Script Runs as SYSTEM Account

If your script runs as a Scheduled Task under SYSTEM, HKCU points to the SYSTEM account's registry hive, which typically has no proxy settings. Your script will report "no proxy" even though every user on the machine has one configured.

Solution: For machine-wide detection, check the HKLM hive or use netsh winhttp show proxy which applies at the system level.

Best Practices and Rules

1. Always Check Multiple Sources

When troubleshooting proxy issues, check the registry, WinHTTP, and environment variables. Different applications use different sources, and a mismatch between them is the most common cause of "it works in the browser but not in the script" problems.

2. Registry Value Names Are Language-Independent

The value names ProxyEnable, ProxyServer, ProxyOverride, and AutoConfigURL are internal identifiers that never change regardless of the Windows display language. This makes registry-based proxy detection safe for international deployment.

3. Don't Forget the Bypass List

The ProxyOverride registry value contains addresses that should not go through the proxy (typically localhost, *.local, or internal company domains). If your script accesses an internal server and gets routed through the proxy unnecessarily, the bypass list may be misconfigured.

4. Use setlocal / endlocal

Always wrap scripts in setlocal and endlocal to prevent variables from leaking into the parent environment.

5. The netsh winhttp Command Is Language-Independent

The command name and parameters (show proxy, set proxy, reset proxy) are the same across all Windows display languages. Only the descriptive output text is translated.

Final Thoughts

Getting the correct proxy settings is a vital diagnostic step for any Batch script that interacts with the internet. Windows maintains proxy configuration at multiple independent levels, user registry, system WinHTTP, and environment variables, and different applications consult different sources. By auditing all three, you build a complete map of how your traffic is being routed and can quickly identify why a specific tool or service fails to connect. The registry value names and netsh command parameters are language-independent, making these scripts reliable across all Windows installations worldwide.