1、启用禁用网卡,

    



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


///<summary>

/// 实现启用或停用本地网络链接

///</summary>

///<param name="netWorkName">本地连接名称</param>

///<param name="operation">操作,传入“启用”或“停用”</param>

staticbool 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;

}


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


    2、修改注册表,改IE设置

    



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


//打开注册表键

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();


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


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

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