试图禁用网络接口
Trying to disable a NetworkInterface
我正在创建一个小工具来管理我的网络接口。
我在网上到处寻找禁用网卡的方法。我已经有它的实例了。
private void disableNic()
{
SelectQuery wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL");
ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);
foreach (ManagementObject item in searchProcedure.Get())
{
if (((string)item["NetConnectionId"]) == Interface.Name)
{
item.InvokeMethod("Disable", null);
}
}
}
void Disable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" disable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
这些函数都没有产生我想要的结果。(事实上它们什么都不做)。我只想禁用网络接口。
有谁知道更好的方法吗?
非常感谢!
使用管理员权限试用应用程序 运行
我正在创建一个小工具来管理我的网络接口。 我在网上到处寻找禁用网卡的方法。我已经有它的实例了。
private void disableNic()
{
SelectQuery wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL");
ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);
foreach (ManagementObject item in searchProcedure.Get())
{
if (((string)item["NetConnectionId"]) == Interface.Name)
{
item.InvokeMethod("Disable", null);
}
}
}
void Disable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" disable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
这些函数都没有产生我想要的结果。(事实上它们什么都不做)。我只想禁用网络接口。
有谁知道更好的方法吗? 非常感谢!
使用管理员权限试用应用程序 运行