本文介绍了更改代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经编写了更改代理设置的代码(基本上保持代理启用和自动LAN设置) 私有 void EnableProxy( bool p) { string k = @ Software \\ \\ Microsoft \ Windows \ CurrentVersion \Internet Settings; Microsoft.Win32.RegistryKey regk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(k, true ); if (p) regk.SetValue( ProxyEnable, 1 ,Microsoft.Win32.RegistryValueKind.DWord); else regk.SetValue( ProxyEnable, 0 ,Microsoft.Win32.RegistryValueKind.DWord); regk.Close(); } 和自动局域网设置 public void IEAutoDetectProxy( bool set ) { // 设置IE设置的代理信息。 RegistryKey RegKey = Registry.CurrentUser.OpenSubKey( @ Software \\Microsoft \\ Windows \\ CurrentVersion \\Internet Settings \\Connections, true ); byte [] defConnection =( byte [])RegKey.GetValue( DefaultConnectionSettings); byte [] savedLegacySetting =( byte [])RegKey.GetValue( SavedLegacySettings); if ( set ) { defConnection [ 8 ] = Convert.ToByte( 9 ); savedLegacySetting [ 8 ] = Convert.ToByte( 9 ); } else { defConnection [ 8 ] = Convert.ToByte( 1 ); savedLegacySetting [ 8 ] = Convert.ToByte( 1 ); } RegKey.SetValue( DefaultConnectionSettings,defConnection); RegKey.SetValue( SavedLegacySettings,savedLegacySetting); } 它有效,但我仍然需要手动应用它。它更改了设置,但我必须转到Internet设置并说确定和应用,请帮助解决方案 通常,当您更改系统范围的设置时,您应该通知应用程序。通常,您可以通过广播特殊类型的消息来完成此操作。所有对该消息感兴趣的人都能够做出反应 - 当然,如果应用程序没有拦截此消息,通知将无法到达。在某些情况下,有特殊技术可以通知特定应用程序。在您的情况下,您还需要通知系统和Internet Explorer。 您应该参考这篇文章:在不重启Internet Explorer的情况下更改Internet Explorer 7代理设置 [ ^ ] I have written a code for Changing Proxy Settings (Basically Stay Between Proxy Enable and Automatic LAN Setting) private void EnableProxy(bool p) { string k = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings"; Microsoft.Win32.RegistryKey regk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(k, true); if (p) regk.SetValue("ProxyEnable", 1, Microsoft.Win32.RegistryValueKind.DWord); else regk.SetValue("ProxyEnable", 0, Microsoft.Win32.RegistryValueKind.DWord); regk.Close(); }and for Automatic LAN settingpublic void IEAutoDetectProxy(bool set) { // Setting Proxy information for IE Settings. RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true); byte[] defConnection = (byte[])RegKey.GetValue("DefaultConnectionSettings"); byte[] savedLegacySetting = (byte[])RegKey.GetValue("SavedLegacySettings"); if (set) { defConnection[8] = Convert.ToByte(9); savedLegacySetting[8] = Convert.ToByte(9); } else { defConnection[8] = Convert.ToByte(1); savedLegacySetting[8] = Convert.ToByte(1); } RegKey.SetValue("DefaultConnectionSettings", defConnection); RegKey.SetValue("SavedLegacySettings", savedLegacySetting); }It works but I still have to apply it manually. It changes the setting but I have to go to Internet Settings and say "OK" and "Apply", Please help 解决方案 In general, when you change system wide settings, you should notify the applications about this. In general, you can do this by broadcasting special kind of messages. All that are interested in that message, will be able to react - of course, if an application does not intercept this message, the notification won't reach it. In some cases there are special techniques to notify specific applications. In your case, you need to notify the system and Internet explorer as well.You should consult this article: Change Internet Explorer 7 Proxy Setting without Restarting Internet Explorer[^] 这篇关于更改代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-30 07:49