【C#】禁用本地连接和修改IE设置

原文链接:https://www.cnblogs.com/stalwart/archive/2011/09/20/2182663.html

        /// <summary>
        /// 实现启用或停用本地网络链接
        /// </summary>
        /// <param name="netWorkName">本地连接名称</param>
        /// <param name="operation">操作,传入“启用”或“停用”</param>
        static bool NetWork(string netWorkName, string operation)
        {
            bool result = false;
            Shell32.Shell shell = new Shell32.ShellClass();
            Shell32.Folder folder = shell.NameSpace(49);
            foreach (Shell32.FolderItem fi in folder.Items())
            {
                if (fi.Name != netWorkName)
                    continue;
                Shell32.ShellFolderItem folderItem = (Shell32.ShellFolderItem)fi;
                foreach (Shell32.FolderItemVerb fiv in folderItem.Verbs())
                {
                    if (!fiv.Name.Contains(operation))
                    { 
                        continue;
                    }
                    else
                    {
                        result = true;
                        fiv.DoIt();
                        Thread.Sleep(1000);
                        break;
                    }
                }
            }
            return result;
        }

2、修改注册表

            //打开注册表键 
            Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);

            //设置自动脚本地址
            rk.SetValue("AutoConfigURL", "");

            txtMessage.Text += "IE自动脚本配置成功!"+"\r\n";

            //设置代理可用 
            rk.SetValue("ProxyEnable", 0);
            //设置代理IP和端口 
            rk.SetValue("ProxyServer", ConfigurationManager.ConnectionStrings["ProxyServer"].ConnectionString);

            txtMessage.Text += "IE代理服务器配置成功!" + "\r\n";
            rk.Close();

源码

posted @ 2024-12-10 10:59  不溯流光  阅读(2)  评论(0编辑  收藏  举报