NetConLibTool.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using NETCONLib;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Azylee.Ext.NetworkX.NetConLibUtils
  7. {
  8. /// <summary>
  9. /// NetConLib 操作工具类
  10. /// </summary>
  11. public static class NetConLibTool
  12. {
  13. /// <summary>
  14. /// 启用所有网络
  15. /// </summary>
  16. public static void Connect()
  17. {
  18. try
  19. {
  20. NetSharingManagerClass netSharingMgr = new NetSharingManagerClass();
  21. INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection;
  22. foreach (INetConnection connection in connections)
  23. {
  24. try { connection.Connect(); } catch { }
  25. // // // //INetConnectionProps connProps = netSharingMgr.get_NetConnectionProps(connection);
  26. // // // //if (connProps.MediaType == tagNETCON_MEDIATYPE.NCM_LAN)
  27. // // // // try { connection.Connect(); } catch { }
  28. }
  29. }
  30. catch { }
  31. }
  32. /// <summary>
  33. /// 禁用所有网络
  34. /// </summary>
  35. public static void Disconnect()
  36. {
  37. try
  38. {
  39. NetSharingManagerClass netSharingMgr = new NetSharingManagerClass();
  40. INetSharingEveryConnectionCollection connections = netSharingMgr.EnumEveryConnection;
  41. foreach (INetConnection connection in connections)
  42. {
  43. try { connection.Disconnect(); } catch { }
  44. }
  45. }
  46. catch { }
  47. }
  48. }
  49. }