关于在C#中如何启用、禁用网卡的代码,多谢。 我的操作系统是XP,有两块网卡,编程工具是C#,请问,如何用程序实现启用、禁用网卡呢?具体的说就是启用第一块网卡的时候,禁用第二块网卡;如果启用第二块网卡的时候,禁用第一块网卡,希望能提供关键代码,多谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //添加引用-COM-浏览-C:\WINDOWS\system32\shell32.dll-添加private bool SetNetworkAdapter(bool status) { const string discVerb = "禁用(&B)"; const string connVerb = "启用(&A)"; const string network = "网络和拨号连接"; const string networkConnection = "本地连接"; string sVerb; if (status) { sVerb = connVerb; } else { sVerb = discVerb; } Shell32.Shell sh = new Shell32.Shell(); Shell32.Folder folder; folder = sh.NameSpace(3); //Shell32.ShellSpecialFolderConstants.ssfCONTROLS try { //进入控制面板的所有选项 foreach (Shell32.FolderItem myItem in folder.Items()) { //进入网络和拔号连接 if (myItem.Name == network) { Shell32.Folder fd = (Shell32.Folder)myItem.GetFolder; foreach (Shell32.FolderItem fi in fd.Items()) { //找到本地连接 if (fi.Name.IndexOf(networkConnection) > -1) { //找本地连接的所有右键功能菜单 foreach (Shell32.FolderItemVerb Fib in fi.Verbs()) { if (Fib.Name == sVerb) { Fib.DoIt(); break; } } } } } } } catch (Exception e) { MessageBox.Show(e.Message); return false; } ; return true; } 用C#写一个xml文件处理工具,求指教 求随机数到指定总和的算法 请教集合参数问题 请高手帮忙:C#如何设定当鼠标移到lable控件上时出现下划线? 我是个C#和.NET的新手,希望与那些和我一样的朋友,或者愿意帮助我们进步的朋友一起学习 求一正则表达式 200分寻数据库连接失败原因? 时间同步问题 分不多了,跪求!循环插入记录 多线程问题:两个线程做类似的工作,只有一个线程工作? 请问一个控件调用问题,感激不尽 如何释放COM资源?
{
const string discVerb = "禁用(&B)";
const string connVerb = "启用(&A)";
const string network = "网络和拨号连接";
const string networkConnection = "本地连接";
string sVerb; if (status)
{
sVerb = connVerb;
}
else
{
sVerb = discVerb;
} Shell32.Shell sh = new Shell32.Shell();
Shell32.Folder folder;
folder = sh.NameSpace(3); //Shell32.ShellSpecialFolderConstants.ssfCONTROLS
try
{
//进入控制面板的所有选项
foreach (Shell32.FolderItem myItem in folder.Items())
{
//进入网络和拔号连接
if (myItem.Name == network)
{
Shell32.Folder fd = (Shell32.Folder)myItem.GetFolder;
foreach (Shell32.FolderItem fi in fd.Items())
{
//找到本地连接
if (fi.Name.IndexOf(networkConnection) > -1)
{
//找本地连接的所有右键功能菜单
foreach (Shell32.FolderItemVerb Fib in fi.Verbs())
{
if (Fib.Name == sVerb)
{
Fib.DoIt();
break;
}
}
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
;
return true;
}