检测网卡的禁用、启用

简介:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace Record
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ManagementClass newClass = new ManagementClass();

//Set up an event watcher and a handler for the event
ManagementEventWatcher networkAdapterArrivalWatcher =
new ManagementEventWatcher("http://www.cnblogs.com/94cool/admin/file://root//wmi",
"SELECT * FROM MSNdis_NotifyAdapterArrival ");

ManagementEventWatcher networkAdapterRemovalWatcher =
new ManagementEventWatcher("http://www.cnblogs.com/94cool/admin/file://root//wmi",
"SELECT * FROM MSNdis_NotifyAdapterRemoval ");

MyHandler handler = new MyHandler();
networkAdapterArrivalWatcher.EventArrived += new EventArrivedEventHandler(handler.Arrived);
networkAdapterRemovalWatcher.EventArrived += new EventArrivedEventHandler(handler.Removed);
//Start watching for events
networkAdapterArrivalWatcher.Start();
networkAdapterRemovalWatcher.Start();
//while (true)
// System.Threading.Thread.Sleep(200000);
//IsNetworkAvailable;
}
}
public class MyHandler
{
public void Arrived(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Network connected");
}

public void Removed(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Network disconnected");
}
}
}




本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/08/14/1545775.html,如需转载请自行联系原作者


相关文章
|
3月前
|
JSON 网络协议 Linux
Shadowsocks多端口启用教程方法
【10月更文挑战第19天】Shadowsocks多端口启用教程方法
215 1
|
4月前
|
块存储
cephx认证及启用和禁用实战
这篇文章介绍了如何在Ceph集群中禁用和启用cephx认证协议,包括修改配置文件、重启服务以及验证配置更改的效果。
76 2
cephx认证及启用和禁用实战
|
8月前
|
弹性计算 运维 Shell
禁用与启用
禁用与启用
129 0
禁用与启用
|
Web App开发 网络协议 网络安全
启用ECH的配置
开启 Encrypted Client Hello (Secure SNI)
5376 0

热门文章

最新文章