代码之家  ›  专栏  ›  技术社区  ›  Boiethios

是否可以设置自动代理(WPAD)并使Chrome意识到这一点?

  •  0
  • Boiethios  · 技术社区  · 7 年前

    我需要设置一个自动配置脚本来设置代理。

    Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings -> AutoConfigURL

    WinHttpDetectAutoProxyConfigUrl 这很好用,但我找不到一个写等效的。

    如何使用Winapi设置autoproxy脚本?

    0 回复  |  直到 7 年前
        1
  •  0
  •   Boiethios    7 年前

    我有一个部分的答案(只针对自动代理的设置)。注册表修改后, InternetInitializeAutoProxyDll 必须打电话。

    下面是一个示例代码:

    [DllImport("wininet.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern int InternetInitializeAutoProxyDll(uint dwReserved);
    
    // ...
    
    registryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
    
    // Setup the registry value:
    registryKey.SetValue("AutoConfigURL", "http://the/config/path");
    
    // Tell Windows to initialize the proxy:
    if (InternetInitializeAutoProxyDll(0) == 0)
    {
        throw new Win32Exception(Marshal.GetLastWin32Error());
    }
    

    但是,当代理未设置时,它不起作用:

    registryKey.DeleteValue(AutomaticProxyRegistryName);
    
    // Does nothing:
    if (InternetInitializeAutoProxyDll(0) == 0)
    {
        throw new Win32Exception(Marshal.GetLastWin32Error());
    }
    
        2
  •  0
  •   Olaf Hess    7 年前

    而不是直接摆弄注册表,我建议通过 WinINet API . 参见 Programmatically Set Browser Proxy Settings in C# 有关如何使用C#执行此操作的信息。问题中提到的代码也可以找到 here .

    编辑

    上面提到的例子也会影响注册表。我有 uploaded