C# 断网

NetSharingManagerClass netSharingMgr = new NetSharingManagerClass(); INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection; foreach (INetConnection connection in connections) { INetConnectionProps connProps = netSharingMgr.get_NetConnectionProps(connection); if (connProps.MediaType == tagNETCON_MEDIATYPE.NCM_LAN) { connection.Disconnect(); //禁用网络 connection.Connect(); //启用网络 } } 需要项目引用COM NetCon,而且在win7/vista下需要管理员权限运行
posted @ 2012-07-16 18:49  adodo1  Views(288)  Comments(0Edit  收藏  举报