none
How to change proxy that do'nt need refresh my system

    Pertanyaan

  • I  want to change my proxy in my app but when I click it first time it changes the proxy and seems to not want to change it again to different proxy. I really need to change proxy multiple times in this application without closing it. What must i do? That  is my code

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using CefSharp.WinForms;
    using CefSharp;
    using Microsoft.Win32;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Runtime.InteropServices;
    
    namespace Change_Proxy
    {
        public partial class Form1 : Form
        {
            RegistryKey dangky;
            RegistryKey dangky2;
            ChromiumWebBrowser chrome;
            int soproxy;
            string ve = string.Concat("", ":", "80");
            string[] teo = new string[5000];
            string[] teo2 = new string[5000];
            // Refesh your system
            [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;
            static bool settingsReturn, refreshReturn;
            // Refesh your system
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                CefSettings settings = new CefSettings();
                Cef.Initialize(settings);
                chrome = new ChromiumWebBrowser("https://www.google.com");
                this.panel1.Controls.Add(chrome);
                chrome.Dock = DockStyle.Fill;
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                 soproxy--;
                //label6.Text = teo[soproxy].ToString();
                dangky = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
                dangky.SetValue("ProxyEnable", 1);
                dangky.SetValue("ProxyServer", teo[soproxy]);
                chrome.Load(site.Text);
                if (soproxy == 0)
                {
                    timer1.Stop();
                    int h = proxy.Lines.Length;
                    string soluong = h.ToString();
                    MessageBox.Show("You have: " + soluong + " traffics");
                    MessageBox.Show("Remember to click Reset");
                }
            }
    
            private void timer2_Tick(object sender, EventArgs e)
            {
                 soproxy--;
                // label6.Text = teo[soproxy].ToString();
                dangky2 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
                dangky2.SetValue("ProxyEnable", 1);
                dangky2.SetValue("ProxyServer", teo[soproxy]);
                //
                chrome.Load(site.Text);
                if (soproxy == 0)
                {
                    timer2.Stop();
                    int h = proxy.Lines.Length;
                    string soluong = h.ToString();
                    MessageBox.Show("You have: " + soluong + " traffics");
                    MessageBox.Show("Remember to click Reset");
                }
            }
    
            private void Traffic_Click(object sender, EventArgs e)
            {
                timer2.Interval = Convert.ToInt32(giay.Text) * 1000;
                teo = Regex.Split(proxy.Text, "\r\n");
                soproxy = teo.Length;
                timer2.Start();
            }
    
            private void view_Click(object sender, EventArgs e)
            {
                timer1.Interval = Convert.ToInt32(giay.Text) * 1000;
                teo = Regex.Split(proxy.Text, "\r\n");
                soproxy = teo.Length;
                timer1.Start();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                // dangky2.SetValue("ProxyEnable", 0);
                dangky2.SetValue("ProxyEnable", 1);
                dangky2.SetValue("ProxyServer", ve);
                dangky2.SetValue("ProxyEnable", 0);
                // refresh your system
                settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
                refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
                //  finish refresh your system
                chrome.Load(site.Text);
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                // dangky.SetValue("ProxyEnable", 0);
                dangky.SetValue("ProxyEnable", 1);
                dangky.SetValue("ProxyServer", ve);
                dangky.SetValue("ProxyEnable", 0);
                // refresh your system
                settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
                refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
                //  finish refresh your system
                chrome.Load(site.Text);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }
    

    Thank you

    Rabu, 12 September 2018 03.16

Semua Balasan

  • You really need to read their FAQ.
    Rabu, 12 September 2018 04.19
  • Hi Quang Rommy,

    This forum discusses and asks questions about the C# programming language, since your issue is more related to cefsharp, which is 3rd-party framework, I would suggest that you could your issue on the following link for suitable support.

    https://github.com/cefsharp/CefSharp

    Thanks for your understanding.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Kamis, 13 September 2018 02.51