为win 7 64位更改IE c#的代理(使用httperbrequest进行测试以确保注册表更改)
我一直在32位上测试我的应用程序,它工作正常,但一旦它切换到64位操作系统,就会出现问题 它更改代理一次,但 它不再保持和测试相同 循环其余部分的代理 .我看到一些帖子显示32位和64位注册表有一些不同,我已经写了一段代码,但在64位环境下不能很好地工作为win 7 64位更改IE c#的代理(使用httperbrequest进行测试以确保注册表更改),c#,windows-7,proxy,32bit-64bit,C#,Windows 7,Proxy,32bit 64bit,我一直在32位上测试我的应用程序,它工作正常,但一旦它切换到64位操作系统,就会出现问题 它更改代理一次,但 它不再保持和测试相同 循环其余部分的代理 .我看到一些帖子显示32位和64位注册表有一些不同,我已经写了一段代码,但在64位环境下不能很好地工作 [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] [return: MarshalAs(Unman
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);
public bool Is64Bit()
{
bool retVal;
IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle, out retVal);
return retVal;
}
Microsoft.Win32.RegistryKey registry;
if (Is64Bit())
{
MessageBox.Show("Oh HO! you are running 64 bit version");
registry = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
}
else
{
MessageBox.Show("Yes it is 32 bit");
registry = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
}
string orignalProxyServer = registry.GetValue("ProxyServer").ToString();
int orignalProxyEnable = int.Parse(registry.GetValue("ProxyEnable").ToString());
int i = 0;
while (i < listBox1.Items.Count)
{
//Enter new proxies Settings//
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", listBox1.Items[i].ToString());
RefreshInternetExplorerSettings();
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");
using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream()))
{
resopnse = reader.ReadToEnd();
this.Invoke(new EventHandler(DoIe));
}
}
catch (Exception c)
{
MessageBox.Show(c.Message);
}
i++;
Application.DoEvents();
backgroundWorker1.ReportProgress(i);
}
registry.SetValue("ProxyEnable", orignalProxyEnable);
registry.SetValue("ProxyServer", orignalProxyServer);
RefreshInternetExplorerSettings();
[DllImport(“kernel32.dll”,SetLastError=true,CallingConvention=CallingConvention.Winapi)]
[返回:Marshallas(UnmanagedType.Bool)]
公共静态外部bool IsWow64Process([In]IntPtr hpprocess,[Out]Out bool lpSystemInfo);
公共bool是64位()
{
布尔-雷特瓦尔;
IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle,out-retVal);
返回返回;
}
Microsoft.Win32.RegistryKey注册表;
if(is64位())
{
Show(“哦,你正在运行64位版本”);
注册表=Microsoft.Win32.registry.CurrentUser.OpenSubKey(“软件\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Internet设置”,true);
}
其他的
{
MessageBox.Show(“是的,它是32位”);
注册表=Microsoft.Win32.registry.CurrentUser.OpenSubKey(“软件\\Microsoft\\Windows\\CurrentVersion\\Internet设置”,true);
}
字符串orignalProxyServer=registry.GetValue(“ProxyServer”).ToString();
int orignalProxyEnable=int.Parse(registry.GetValue(“ProxyEnable”).ToString();
int i=0;
而(i
如果只需要为HttpWebRequest设置代理,可以这样做
req.Proxy = new WebProxy(listBox1.Items[i].ToString());
不要更改注册表设置。如果只需要为HttpWebRequest设置代理,您可以这样做
req.Proxy = new WebProxy(listBox1.Items[i].ToString());
与更改注册表设置不同。似乎对Internet Explorer的版本及其使用的注册表节点有很大的依赖性: 对于基于Windowsx86的计算机: 要更改机器范围的连接尝试,请执行以下操作: HKEY\ U本地\计算机\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改用户特定的连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 对于基于Windowsx64的计算机: 要更改Internet Explorer 32位计算机范围的连接尝试,请执行以下操作: HKEY\U LOCAL\U MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 32位的用户特定连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 64位计算机范围的连接尝试,请执行以下操作: HKEY\ U本地\计算机\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 64位的用户特定连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 资料来源:
我建议您尝试在x86和x64系统中使用相同的节点。似乎对Internet Explorer的版本及其使用的注册表节点有很大的依赖性: 对于基于Windowsx86的计算机: 要更改机器范围的连接尝试,请执行以下操作: HKEY\ U本地\计算机\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改用户特定的连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 对于基于Windowsx64的计算机: 要更改Internet Explorer 32位计算机范围的连接尝试,请执行以下操作: HKEY\U LOCAL\U MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 32位的用户特定连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 64位计算机范围的连接尝试,请执行以下操作: HKEY\ U本地\计算机\软件\ Microsoft\Windows\CurrentVersion\Internet设置 要更改Internet Explorer 64位的用户特定连接尝试,请执行以下操作: HKEY\U当前用户\软件\ Microsoft\Windows\CurrentVersion\Internet设置 资料来源:
我建议您尝试在x86和x64系统中使用相同的节点。您认为您在做什么?你想用这些代码实现什么?你真的认为WebRequest每次调用时都会停止并读取注册表吗?也许我错了,但我希望WebRequest能够做到“在64位环境下不能很好地工作”?你能描述一下问题本身吗?补充的问题陈述请阅读。谢谢你指出你认为你在做什么?你想用这些代码实现什么?你真的认为WebRequest会停止并读取注册表吗