通过MSFT_NetAdapter使能/禁用网卡
Enable/Disable of the network adapter through MSFT_NetAdapter
我正在尝试在Windows 8操作系统中通过MSFT_NetAdapter禁用/启用网络适配器。
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=Delegate," _
& "authenticationLevel=pktPrivacy}rootstandardcimv2")
Set colSettings = objWMIService.ExecQuery("Select * from MSFT_NetAdapter")
For Each objOperatingSystem in colSettings
Wscript.Echo _
"DeviceID: " & objOperatingSystem.DeviceID & vbCrLf & _
"Name: " & objOperatingSystem.Name
objOperatingSystem.Disable
Next
例如只使用Disable。MSFT_NetAdapter返回"DeviceID"或"Name",当你调用objOperatingSystem方法时。禁用获取错误0x80041003 "当前用户没有执行操作的权限"。我试着用这个代码:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=Delegate," _
& "authenticationLevel=pktPrivacy}rootcimv2")
Set colSettings = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where PhysicalAdapter = true")
For Each objOperatingSystem in colSettings
Wscript.Echo _
"DeviceID: " & objOperatingSystem.DeviceID & vbCrLf & _
"Name: " & objOperatingSystem.Name
objOperatingSystem.Disable
Next
此代码在windows 7上运行良好。执行完代码后,立即切换网络适配器。在windows 8操作系统中,禁用/启用需要在代码后重新启动系统。windows 8操作系统下如何管理网卡
您需要以管理员权限运行。如果您的应用程序将由没有管理员权限的用户运行,那么您可以安装与您的应用程序通信的服务。
此代码禁用所有网络适配器。
//
// In Windows Vista this can be accomplished through a simple WMI query.
//
try
{
using (var query = new ManagementObjectSearcher("select * from Win32_NetworkAdapter where NetConnectionStatus = 2"))
{
using (var devices = query.Get())
{
foreach (ManagementObject device in devices)
{
try
{
device.InvokeMethod("Disable", null);
}
catch (Exception ex)
{
}
}
}
}
}
catch (Exception ex)
{
}
相关文章:
- C++程序在将 int 与 cin 一起使用时有效,但不能使用字符串
- 不能使这种类型的"void(C::* volatile)(int) const "在参考手册C++示
- C++:不能使运算符<<成为模板嵌套类的好友
- 多个boost io_service在单独的线程上用于多个网卡
- 网卡的 TX/RX 缓冲区中的数据如何传输到 dpdk 环形缓冲区而不是内核环形缓冲区
- 为什么我不能使私人运营商成为新的并使用默认实现?
- 有没有办法使成员函数不能从构造函数调用
- C++:强制实施函数,使其不能接受按值传递的任何参数
- 不能使外部类成为内部类内的成员对象
- 为什么我不能使对象 m1
- 如何在给定设备实例ID的情况下可靠快速地获取网卡的MAC地址
- 强制无线网卡只扫描一个通道(以程序方式)
- 以编程方式确定网卡在Windows上是集成的还是分立的
- libpcap捕获10gbps网卡
- 如何更改以太网数据包(来自网卡的数据包)?我可以使用Netfilter钩子吗?
- 使用Windows API检测网卡和以太网设备的IP地址
- 如何在Code::Blocks上使能SSE/SSE2
- 如何以编程方式确定网卡是虚拟网卡
- SFINAE使能非模板成员功能
- 通过MSFT_NetAdapter使能/禁用网卡