You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemProxy.cs 1.8 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace shadowsocks_csharp
  7. {
  8. class SystemProxy
  9. {
  10. [DllImport("wininet.dll")]
  11. public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
  12. public const int INTERNET_OPTION_SETTINGS_CHANGED = 39;
  13. public const int INTERNET_OPTION_REFRESH = 37;
  14. static bool settingsReturn, refreshReturn;
  15. public static void NotifyIE()
  16. {
  17. // These lines implement the Interface in the beginning of program
  18. // They cause the OS to refresh the settings, causing IP to realy update
  19. settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
  20. refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
  21. }
  22. public static void Enable()
  23. {
  24. RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
  25. registry.SetValue("ProxyEnable", 0);
  26. registry.SetValue("ProxyServer", "");
  27. registry.SetValue("AutoConfigURL", "http://127.0.0.1:8090/pac");
  28. SystemProxy.NotifyIE();
  29. }
  30. public static void Disable()
  31. {
  32. RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
  33. registry.SetValue("ProxyEnable", 0);
  34. registry.SetValue("ProxyServer", "");
  35. registry.SetValue("AutoConfigURL", "");
  36. SystemProxy.NotifyIE();
  37. }
  38. }
  39. }