C# 如何动态更改IE代理设置

C# 如何动态更改IE代理设置,c#,.net,internet-explorer,proxy,C#,.net,Internet Explorer,Proxy,我已经编写了一个VSTS数据驱动测试用例。我需要更新个别测试用例的IE代理设置。我已经编写了以下代码行来更改代理 RegistryKey reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", true); string va = reg.GetValue("DefaultConnectionSettings").ToStri

我已经编写了一个VSTS数据驱动测试用例。我需要更新个别测试用例的IE代理设置。我已经编写了以下代码行来更改代理

RegistryKey reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", true);
string va = reg.GetValue("DefaultConnectionSettings").ToString();
reg.SetValue("DefaultConnectionSettings", @"hex:3c,00,00,00,15,00,00,00,01,00,00,00,0e,00,00,\00,31,32,37,2e,30,2e,30,2e,31,3a,38,30,38,30,09,00,00,00,6c,6f,63,61,6c,68,\6f,73,74,0b,00,00,00,31,31,31,2e,31,31,2e,31,31,31,31,01,00,00,00,00,00,00,\00,30,fd,35,de,8d,27,c6,01,03,00,00,00,c0,a8,01,73,c0,a8,b8,01,c0,a8,85,01,\00,00,00,00,00,00,00,00 ");

RegistryKey RegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
RegKey.SetValue("ProxyServer", "proxyvalue");
RegKey.SetValue("ProxyEnable", 1);
它会更改第一个测试用例的代理,但不会更改第二个测试用例的代理


请帮助确定我在这里做错了什么。

实际上我没有测试它,但我认为IE只会在启动时读取注册表值。因此,在更改这些值并开始新测试之前,请确保关闭所有IE进程。

我没有直接调用任何IE进程,但我使用了process class,它调用了一些命令行工具,该工具打开了IE。我在每次测试用例运行后都尝试关闭该进程。这并不能解决我的问题。