Question How can i disable my C# application proxy server error

dogankemal

New member
Joined
Dec 9, 2020
Messages
1
Programming Experience
3-5
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

C#:
public static class Proxy
 {
     [DllImport("wininet.dll")]
     public static extern bool InternetSetOption
     (IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
    
     public const int INTERNET_OPTION_SETTINGS_CHANGED = 39;
     public const int INTERNET_OPTION_REFRESH = 37;
    
     public static bool Kapat()
     {
         bool Sonuc = false;
    
         try
         {
             bool settingsReturn, refreshReturn;
             RegistryKey registry = Registry.CurrentUser.OpenSubKey
            ("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
             registry.SetValue("ProxyEnable", 0);
             registry.SetValue("ProxyServer", 0);
    
             if ((int)registry.GetValue("ProxyEnable", 1) == 1)
             {
                 Sonuc = false;
             }
             else
             {
                 Sonuc = true;
             }
    
             registry.Close();
             settingsReturn = InternetSetOption
             (IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
             refreshReturn = InternetSetOption
             (IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
         }
         catch (Exception)
         {
             Sonuc = false;
         }
    
         return Sonuc;
     }
 }

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 !
 
Crossposted on StackOverflow : How can i disable my C# application proxy server error

Is the code above the same code also running in your second app?
some users can shutdown computer without closing my app.
Can you elaborate on this?
Consider using the FormClosing Event to perform any actions should windows be shut down. There are ways to tell windows to wait until your application completes operations and you can force windows to wait for those operations to complete before it shuts down. You may find the suggestions I provided here useful in such situations : detects shutdown and stops it

Also, if you don't mind, can you explain what the purpose of your application is?
 
Back
Top Bottom