//禁用 SetNetworkAdapter(False)
//启用 SetNetworkAdapter(True)
//添加引用system32/shell32.dll
private static bool SetNetworkAdapter(bool status)
{
const string discVerb = "停用(&B)"; // "停用(&B)";
const string connVerb = "启用(&A)"; // "启用(&A)";
const string network = "网络连接"; //"网络连接";
const string networkConnection = "VMware Network Adapter VMnet1"; // "本地连接" string sVerb = null; if (status)
{
sVerb = connVerb;
}
else
{
sVerb = discVerb;
} Shell32.Shell sh = new Shell32.Shell();
Shell32.Folder folder = sh.NameSpace(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 == networkConnection))
{
//找本地连接的所有右键功能菜单
foreach (Shell32.FolderItemVerb Fib in fi.Verbs())
{
if (Fib.Name == sVerb)
{
Fib.DoIt();
return true;
}
}
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
return true;
}

第一种出处:http://blog.csdn.net/leon_ice/article/details/4426278

再来一种方式 其实大体上是一样的 只不过第二种个人觉得比较赞 win7也适用

          /// <summary>
/// 启用网络
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_StartNet_Click(object sender, EventArgs e)
{
//SetNetworkAdapter(true); SetTest("本地连接", "启用"); // SetTest("本地连接", "禁用");
} private void SetTest(string netWorkName, string operation)
{
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
{
fiv.DoIt();
Thread.Sleep(1000);
break;
}
}
}
}

shell32.dll 控制网络的更多相关文章

  1. C#应用Newtonsoft.Json.dll,控制json的时间格式

    原文:C#应用Newtonsoft.Json.dll,控制json的时间格式 var aIsoDateTimeConverter = new IsoDateTimeConverter();aIsoDa ...

  2. Linux模拟控制网络时延

    之前以为可以使用Linux自带的工具模拟控制网络时延,所以上网找了一些资料.后来发现,找到的资料目前只支持在一个网卡上模拟发送报文的时延,而不能设置有差别的网络时延,或者说当要模拟的向A发送的时延与要 ...

  3. 自学工业控制网络之路1.1-工业控制系统发展历程CCS DCS FCS

    返回 自学工业控制网络之路 自学工业控制网络之路1.1-工业控制系统发展历程CCS DCS FCS 工业控制系统是对诸如图像.语音信号等大数据量.高速率传输的要求,又催生了当前在商业领域风靡的以太网与 ...

  4. 自学工业控制网络之路1.2-典型的现场总线介绍PROFIBUS

    返回 自学工业控制网络之路 自学工业控制网络之路1.2-典型的现场总线介绍PROFIBUS 目前看来,现场总线标准不会统一,多标准并存现象将会持续. 现场总线国家标准: 中国的DeviceNet和AS ...

  5. 自学工业控制网络之路1.3-典型的现场总线介绍FF

    返回 自学工业控制网络之路 自学工业控制网络之路1.3-典型的现场总线介绍FF 1994年6月,ISP和WORLDFIP合并成立现场总线基金会FF.1998年,FF基金会开发了HSE 10/100Mb ...

  6. 自学工业控制网络之路1.4-典型的现场总线介绍CAN

    返回 自学工业控制网络之路 自学工业控制网络之路1.4-典型的现场总线介绍CAN 1991年3月,发布了CAN技术贵干v2.0,包含了A.B两部分.CAN2.0A给出报文标准格式,CAN2.0B给出了 ...

  7. 自学工业控制网络之路1.5-典型的现场总线介绍DeviceNet

    返回 自学工业控制网络之路 自学工业控制网络之路1.5-典型的现场总线介绍DeviceNet 2002年10月DeviceNet被批准为中国国家标准GB/T18858.3-2002,并于2003.4. ...

  8. 自学工业控制网络之路1.6-典型的现场总线介绍Interbus

    返回 自学工业控制网络之路 自学工业控制网络之路1.6-典型的现场总线介绍Interbus 1987年正式公布,其主要技术开发者为德国的PhoenixContact公司.1996年,INTERBUS成 ...

  9. 自学工业控制网络之路2.2-PROFINET

    返回 自学工业控制网络之路 自学工业控制网络之路2.2-PROFINET PROFINET由PROFIBUS国际组织(PROFIBUS International,PI)推出,是新一代基于工业以太网技 ...

随机推荐

  1. sql查询优化策略

    Sql语句执行顺序: 查询的逻辑执行顺序 (1) FROM left_table (3) join_type JOIN right_table (2) ON join_condition (4) WH ...

  2. Consider defining a bean named 'entityManagerFactory' in your configuration解决办法

    错误信息: *************************** APPLICATION FAILED TO START *************************** Descriptio ...

  3. 十五、过滤器(Filter)

    过滤器(Filter) 过滤器概述 1 什么是过滤器 过滤器JavaWeb三大组件之一,它与Servlet很相似!不它过滤器是用来拦截请求的,而不是处理请求的. 当用户请求某个Servlet时,会先执 ...

  4. 高效求a的n次幂的算法

    代码: public class A的N次幂 { public static void main(String[] args) { int a = 2; int n = 60; long t = Sy ...

  5. Java线程池核心原理剖析

    在系统开发时,我们经常会遇到“池”的概念.使用池一种以空间换时间的做法,通常在内存中事先保存一系列整装待命的对象,以供后期供其他对象随时调用.常见的池有:数据库连接池,socket连接池,线程池等.今 ...

  6. [Swift]LeetCode218. 天际线问题 | The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  7. [Swift]LeetCode319. 灯泡开关 | Bulb Switcher

    There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...

  8. [Swift]LeetCode675. 为高尔夫比赛砍树 | Cut Off Trees for Golf Event

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  9. [Swift]LeetCode705. 设计哈希集合 | Design HashSet

    Design a HashSet without using any built-in hash table libraries. To be specific, your design should ...

  10. postgresql 删除库的时候报错database "temp_test_yang" is being accessed by other users

    删除库的时候报错 ERROR: database "temp_test_yang" is being accessed by other usersDETAIL: There ar ...