How can i disable my C# application proxy server error

Dec 9 2020 4:19 AM
I am using a proxy server on my C# app. If the app is running, the proxy server is active, if app is not running or crashed, I can disable proxy server but some users can shutdown computer without closing my app. When the computer is turned on, then proxy server is active, but my app is not running. After that they want to use internet but they have to "check your proxy server bla bla" until run my app or disabled from internet explorer.
By the way I wrote small, secondly .exe and it is running at system tray but some antiviruses and some times windows defender giving us "false positive". You can see how is changing regedit
  1. public static class Proxy  
  2. {  
  3. [DllImport("wininet.dll")]  
  4. public static extern bool InternetSetOption  
  5. (IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);  
  6. public const int INTERNET_OPTION_SETTINGS_CHANGED = 39;  
  7. public const int INTERNET_OPTION_REFRESH = 37;  
  8. public static bool Kapat()  
  9. {  
  10. bool Sonuc = false;  
  11. try  
  12. {  
  13. bool settingsReturn, refreshReturn;  
  14. RegistryKey registry = Registry.CurrentUser.OpenSubKey  
  15. ("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"true);  
  16. registry.SetValue("ProxyEnable", 0);  
  17. registry.SetValue("ProxyServer", 0);  
  18. if ((int)registry.GetValue("ProxyEnable", 1) == 1)  
  19. {  
  20. Sonuc = false;  
  21. }  
  22. else  
  23. {  
  24. Sonuc = true;  
  25. }  
  26. registry.Close();  
  27. settingsReturn = InternetSetOption  
  28. (IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);  
  29. refreshReturn = InternetSetOption  
  30. (IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);  
  31. }  
  32. catch (Exception)  
  33. {  
  34. Sonuc = false;  
  35. }  
  36. return Sonuc;  
  37. }  
  38. } 

I have two question;

  1. How can I disable before when users shutdown computers without register?

  2. How can I change register keys in a safer way?

Thank you again!