如何从 C# 访问 Registry 以获取代理? [英] How do I access Registry from C# for a proxy?
问题描述
所以我之前问过这个问题:
So I've previously asked this question:
如何使用 winforms webbrowser 控件将套接字指向代理 IP/端口?这Visual C#.NET 附带的标准 Web 浏览器.
How do I point a socket to the proxy ip/port using the winforms webbrowser control? The standard web browser that comes with Visual C#.NET.
请在 Visual C#.NET 方面提供帮助.
Please help in Visual C#.NET.
我收到一条回复,告诉我WebBrowser 只是 IE 上的一个界面.要设置IE代理设置,可以破解注册表!"
I got a response telling me that "WebBrowser is just an interface over IE. To set the IE proxy settings, you can hack the registry!"
他让我添加以下代码:
string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
string serverName = "";//your proxy server name;
string port = ""; //your proxy port;
string proxy = serverName + ":" + port;
RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
RegKey.SetValue("ProxyServer", proxy);
RegKey.SetValue("ProxyEnable", 1);
当然,这可能会添加到按钮点击事件之类的东西中,我需要添加代理和端口.
Of course, this might be added to something like a button clicked event, and I would need to add in the proxy and port.
问题是找不到 RegistryKey,因为我缺少 using 指令或程序集引用,并且 Registry 在当前上下文中不存在.
The problem is that RegistryKey could not be found because I'm either missing a using directive or an assembly reference, and Registry does not exist in the current context.
我假设我缺少这两个的 using 指令,但我不知道.
I'm assuming I'm missing a using directive for both of those, but I don't know.
如何在 Visual C#.NET 中解决这个问题?
How do I fix this problem in Visual C#.NET?
推荐答案
正如我在上一个问题中所评论的.
As I commented in the previous question.
using Microsoft.Win32;
参见 http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey(v=VS.80).aspx
这篇关于如何从 C# 访问 Registry 以获取代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!