Dynamically set the IE proxy server, do not restart IE

xiaoxiao2021-03-05  55

[DllImport (@ "wininet", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "InternetSetOption", CallingConvention = CallingConvention.StdCall)] public static extern bool InternetSetOption (int hInternet, int dmOption, IntPtr lpBuffer, int dwBufferLength);

public static void SetProxy () {// Open the Registry RegistryKey regKey = Registry.CurrentUser; string SubKeyPath = @ "Software / Microsoft / Windows / CurrentVersion / Internet Settings"; RegistryKey optionKey = regKey.OpenSubKey (SubKeyPath, true); // Change the nuise, set the agent, OptionKey.SetValue ("proxyenable", 1); OptionKey.SetValue ("ProxyServer", "192.168.1.85:80");

// Activate the agent set InternetSetoption (0,39, INTPTR.ZERO, 0); InternetSetoption (0,37, INTPTR.ZERO, 0);}

转载请注明原文地址:https://www.9cbs.com/read-31839.html

New Post(0)