Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Windows 10如何代理更改?_C#_Proxy_Registry_Dllimport - Fatal编程技术网

C#Windows 10如何代理更改?

C#Windows 10如何代理更改?,c#,proxy,registry,dllimport,C#,Proxy,Registry,Dllimport,我需要更改Windows 10代理。但我的代码不起作用。如果我使proxyactive ethernet运行:( 这是我的密码 [DllImport("wininet.dll")] public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength); public const int INTERNET_OPTION_

我需要更改Windows 10代理。但我的代码不起作用。如果我使proxyactive ethernet运行:(

这是我的密码

    [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;

   public static void proxyactive()
    {
        RegistryKey RegKey1 = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);

        RegKey1.SetValue("ProxyServer", Globals.MainWindow.txtProxy.Text);
        RegKey1.SetValue("ProxyEnable", 1);

       // These lines implement the Interface in the beginning of program 
        // They cause the OS to refresh the settings, causing IP to realy update
        settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
        refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);

    }


 public static void proxydeactive()
    {
        RegistryKey RegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);

        RegKey.SetValue("ProxyServer", Globals.MainWindow.txtProxy.Text);
        RegKey.SetValue("ProxyEnable", 0);


        settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
        refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);

    }

谢谢您的帮助。

您好,欢迎使用SO。您没有说明您遇到了什么错误,也没有说明您试图输入什么输入值。请妥善设置问题格式和代码。请展示您所做的一些努力,以期望人们努力回答您的问题。您甚至没有让我们尝试正确调试您的应用程序。也许可以尝试运行您的应用程序提升权限。