0% found this document useful (0 votes)
215 views2 pages

Win7 Proxy Findings

The document discusses different ways to programmatically determine a system's proxy settings in Windows using the WinHTTP API. It outlines 3 cases - when a simple proxy, PAC file, or WPAD is configured - and the appropriate WinHTTP functions to use to retrieve the proxy information for each case, such as WinHttpGetIEProxyConfigForCurrentUser, WinHttpGetProxyForUrl, and WinHttpGetProxyForUrlEx. Complete examples are provided in the linked MSDN documentation.

Uploaded by

Pranay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views2 pages

Win7 Proxy Findings

The document discusses different ways to programmatically determine a system's proxy settings in Windows using the WinHTTP API. It outlines 3 cases - when a simple proxy, PAC file, or WPAD is configured - and the appropriate WinHTTP functions to use to retrieve the proxy information for each case, such as WinHttpGetIEProxyConfigForCurrentUser, WinHttpGetProxyForUrl, and WinHttpGetProxyForUrlEx. Complete examples are provided in the linked MSDN documentation.

Uploaded by

Pranay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

IN WinHttpOpen(..) [ https://msdn.microsoft.

com/en-
us/library/windows/desktop/aa384098(v=vs.85).aspx ] currently we use
WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY (works on 8.1 & above)

Currently we are doing this: WinHttpOpen(nullptr, WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY,


WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, NULL);

=======================================================================

WINHTTP_ACCESS_TYPE_DEFAULT_PROXY is the flag which doesn’t inherit browser proxy settings &
which is why prob. it worked for all 3 combos (Basic, Basic+PAC, Basic+WPAD) even when the
credentials were not present.

======================================================================

If we use WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*
lProxyInfo)

Where WINHTTP_CURRENT_USER_IE_PROXY_CONFIG is

typedef struct {
BOOL fAutoDetect; => if true, should imply WPAD conf.(Web Proxy Auto-Discovery) : CASE 3
LPWSTR lpszAutoConfigUrl; => if not null & fAutoDetect is false implies PAC conf. & this string has URL
for PAC file : CASE 2
LPWSTR lpszProxy; => If both above are not set, implies simple proxy & proxy URL is this : CASE 1
LPWSTR lpszProxyBypass; // bypass URLs
} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;

=====================================================================

CASE :1

For BASIC simple only proxy if we try this => works


WinHttpOpen(nullptr, WINHTTP_ACCESS_TYPE_NAMED_PROXY, lProxyInfo.lpszProxy,
lProxyInfo.lpszProxyBypass, NULL);

=====================================================================

CASE :3

If WPAD conf (fAutoDetect is true) we can use WinHttpGetProxyForUrl to retrieve the proxy for the
request as mentioned here (https://msdn.microsoft.com/en-
us/library/windows/desktop/aa384075(v=vs.85).aspx) in form of WINHTTP_PROXY_INFO .

struct WINHTTP_PROXY_INFO {
DWORD dwAccessType;
LPWSTR lpszProxy;
LPWSTR lpszProxyBypass;
};
As WinHttpGetProxyForUrl uses WINHTTP_AUTOPROXY_OPTIONS which we can set as per our req.
(https://msdn.microsoft.com/en-us/library/windows/desktop/aa384123(v=vs.85).aspx) and

[ Note: WPAD we set via this registry=> HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet ->
services -> Tcpip -> Parameters]

=======================================================================

CASE :2

If PAC (lpszAutoConfigUrl is set & AutoDetect False) we should try to get proxy URL using this structure
WINHTTP_AUTOPROXY_OPTIONS config as input for WinHttpGetProxyForUrl / WinHttpGetProxyForUrl
Ex & we get output WINHTTP_PROXY_INFO which has proxy config details.

==================================================================

Complete Examples are here: https://msdn.microsoft.com/en-


us/library/windows/desktop/aa384122(v=vs.85).aspx as well

==================================================================

Other useful functions – WinHttpDetectAutoProxyConfigUrl, WinHttpGetProxyForUrlEx,


WinHttpCreateProxyResolver

You might also like