无法访问IE代理设置C# [英] Cannot Access IE Proxy settings C#

查看:97
本文介绍了无法访问IE代理设置C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试为C#中的阅读IE代理设置提供解决方案。我需要阅读所有选项,自动检测设置,自动配置URL和手动代理设置。

1)我尝试使用Interop Services - WinHTTP.DLL,它确实有效,但我应该只使用C#的东西

2)我尝试了同样的阅读注册表,并取得了成功,但我不应该使用这个解决方案。

3)我尝试使用System.Net.Configuration,但我无法使用代码获取默认的系统代理设置: -

// System.Net.Configuratiion
System。 Net.Configuration.ProxyElement proxyConf = new ProxyElement();
//proxyConf.UseSystemDefault = ProxyElement.UseSystemDefaultValues.True;

if(proxyConf.AutoDetect == ProxyElement.AutoDetectValues.True)
Console .WriteLine(" Auto detect Proxy");
if(proxyConf.ScriptLocation!= null)
{
Console.WriteLine(" Auto Config Script");
Console.WriteLine(proxyConf) .ScriptLocation);
}

if(proxyConf.ProxyAddress!= null)
{
Console.WriteLine(proxyConf.ProxyAddress);
}

它根本没有为我获取系统设置。

3)我尝试过System.Web.Configuration,但仍然没用。


4 )我不能使用Webbrowser控件。

我该怎么做。
任何帮助woul; d非常感谢

解决方案

当其他所有方法都失败时,可以去WMI做任何事情。你也可以将它转换为C#...注意:然而,所有这一切都在改变reg。值。这个样本是从Inet中提取的,不是我自己的工作。
























< td style ="background-color:#f7f7f7">

























Dim KeyVals
Const HK EY_CURRENT_USER =& H80000001
strComputer = "。"
设置 objRegistry = GetObject( " winmgmts:\\" &安培;将strComputer&安培;
" \root\default:StdRegProv"
设置 oShell = CreateObject( " WScript.Shell"
strKeyPath = "software \ Microsoft \ Windows \ CurrentVersion \Internet
设置"
strValueName = " ProxyOverride"
keyvals =
oShell.RegRead( " HKCU\software\Microsoft\Windows\CurrentVersion\Internet
Settings \ProxyOverride"
如果 InStr(1, keyvals, " 172.16.48.30" ,1)= 0 THEN
keyvals = keyvals& " 172.16.48.30"
objRegistry.setStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,
keyvals
结束 如果

Hi All,

I am currently trying to workout a solution for Reading IE Proxy settings in C#. I need to read all the option, automatically detect settings , Autoconfiguration url and manual proxy settings.

1) I tried using Interop Services - WinHTTP.DLL, it did work, but I am supposed to use only C# stuff

2) I tried reading registry fro the same, and was successful, but iam not supposed to use thsi solution.

3) I tried using System.Net.Configuration, but the I cannot fetch the default System Proxy settings using the code :-

  //System.Net.Configuratiion
            System.Net.Configuration.ProxyElement proxyConf = new ProxyElement() ;
             //proxyConf.UseSystemDefault = ProxyElement.UseSystemDefaultValues.True;

            if ( proxyConf.AutoDetect == ProxyElement.AutoDetectValues.True )
                Console.WriteLine("Auto detect Proxy");
            if (proxyConf.ScriptLocation != null)
            {
                Console.WriteLine(" Auto Config Script");
                Console.WriteLine(proxyConf.ScriptLocation);
            }

            if (proxyConf.ProxyAddress != null)
            {
                Console.WriteLine(proxyConf.ProxyAddress);
            }

It simply does not fetch the system settings for me.

3) I tried System.Web.Configuration, but still no use.


4) I cannot use Webbrowser control.

How do I do it.
Any help woul;d be greatly appreciated

解决方案

Well when all else fails, one can go to WMI to do anything. You can convert this to C# too if you want...Note: However, that all this is doing is changing the reg. values. This sample was lifted from the Inet and is not my own work.

Dim KeyVals  
 
Const HKEY_CURRENT_USER = &H80000001  
 
strComputer = "." 
Set objRegistry = GetObject("winmgmts:\\" & strComputer &  
"\root\default:StdRegProv")  
Set oShell = CreateObject("WScript.Shell")  
 
strKeyPath = "software\Microsoft\Windows\CurrentVersion\Internet
Settings" 
 
strValueName = "ProxyOverride" 
keyvals =  
oShell.RegRead("HKCU\software\Microsoft\Windows\CurrentVersion\Internet
Settings\ProxyOverride")  
 
If InStr(1,keyvals,"172.16.48.30",1)=0 THEN  
keyvals = keyvals & "172.16.48.30" 
objRegistry.setStringValue HKEY_CURRENT_USER, strKeyPath, strValueName,  
keyvals  
End If 


这篇关于无法访问IE代理设置C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆