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

    已好多天没有写博客了,由于公司最近网络有改变,上网要算钱,晕拉,所有就找了上网卡来上网,但是用了无线,局域网就上不去了。

来回切网还有改代理设置有点麻烦,所有就写了个小软件,已便自己方便。

    这个小软件主要有二点功能,1、是启用禁用网卡,根据名称来设置 2、通过修改注册表来改IE设置

    现贴两段代码上来

    1、启用禁用网卡,这个是网上找的

    

///   <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、修改注册表,改IE设置

    

// 打开注册表键 
            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();

    比较简单只是为了自己方便。

    一些设置是可以在config文件里配置的。

    源码

    

转载于:https://www.cnblogs.com/stalwart/archive/2011/09/20/2182663.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值