检测网卡的禁用、启用

简介:

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,如需转载请自行联系原作者


相关文章
|
14天前
|
弹性计算 运维 Shell
|
4月前
|
监控 网络协议 Linux
防火墙规则动态管理器 - firewalld
【1月更文挑战第11天】
53 0
|
Web App开发 网络协议 网络安全
启用ECH的配置
开启 Encrypted Client Hello (Secure SNI)
4080 0
禁用与启用
禁用与启用
90 0
禁用与启用
|
Linux
Linux网络管理之网卡、网络接口开关设置
ifup命令用于激活指定的网络接口。ifup命令会去读取/etc/sysconfig/network-scripts/目录下的相关网络接口的配置文件,并根据配置文件的内容来激活该网络接口。
653 0
Linux网络管理之网卡、网络接口开关设置
|
Shell
Win系统 - Devcon 启用 / 禁用设备、驱动程序
Win系统 - Devcon 启用 / 禁用设备、驱动程序
405 0
|
Linux
18.13 SELinux策略规则的开启和关闭
默认情况下,并不是所有的规则都处于开启状态,因此,虽然我们无需修改规则的具体内容,但学习如何开启和关闭规则,还是很有必要的。
198 0
18.13 SELinux策略规则的开启和关闭
|
安全 Windows 网络安全
我的电脑已经禁ping,应该如何启用该功能?
我的电脑已经禁ping,应该如何启用该功能? "禁止Ping入"是防止别人攻击你的, 首先,先明白ping命令,主要功能是测试网络联通性,如果组织ping入的话,别的机器或者是其他病毒程序在一定程度上能够跳过你的机器,从而让你免受入侵或攻击。
2244 0