如何以编程方式禁用(或重置)的网络适配器,在C# [英] How to disable (or reset) a network adapter programmatically in C#

查看:461
本文介绍了如何以编程方式禁用(或重置)的网络适配器,在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Windows XP编程方式禁用的网络适配器使用C#(.NET 2.0)嵌入式。

I need to disable a network adapter programmatically using C# (.NET 2.0) on Windows XP Embedded.

背景原因:在PC上安装蓝牙堆栈后,蓝牙PAN适配器模块蓝牙管理程序(运行在系统托盘中)。如果我取消了蓝牙PAN那么蓝牙管理器工作正常。

Background Reason: After installing a Bluetooth stack on the PC, the Bluetooth PAN adapter blocks the Bluetooth manager program (that runs in the system tray). If I disable the Bluetooth PAN then the Bluetooth manager works fine.

此问题在Windows XP Embedded的计算机只发生。

This issue is happening only on Windows XP Embedded machines.

推荐答案

如果你想使用在设备管理器中显示它可能会更容易使用WMI的名字。查询

If you want to use the name shown in device manager it is probably going to be easier to use WMI. A query

SELECT * FROM Win32_NetworkAdpater WHERE NName='name from device mnanager'

将选择一个 WMI对象 禁用 的方法。

will select a WMI object with a Disable method.

像这样的东西给一个设备名称瑞昱的PCIe GBE系列控制器:

Something like this given a device name "Realtek PCIe GBE Family Controller":

var searcher = new ManagementObjectSearcher("select * from win32_networkadapter where Name='Realtek PCIe GBE Family Controller'");
var found = searcher.Get();
var nicObj = found.First() as ManagementObject; // Need to cast from ManagementBaseObject to get access to InvokeMethod.

var result = (uint)nicObj.InvokeMethod("Disable"); // 0 => success; otherwise error.

NB 的。如的Netsh 这将需要提升执行禁用(但不包括查询)。

NB. like Netsh this will require elevation to perform the disable (but not for the query).

这篇关于如何以编程方式禁用(或重置)的网络适配器,在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆