[英]Trying to disable a NetworkInterface
I'm creating little tool to manage my NetworkInterfaces. 我正在创建管理我的NetworkInterfaces的小工具。 I've looked all over the web for a way to disable a nic.
我在网上寻找了一种禁用nic的方法。 I've already got an instance of it.
我已经有一个实例。
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();
}
Neither of these functions produce the result that i want.(in fact they don't do anything). 这些功能都不产生我想要的结果。(实际上,它们什么都不做)。 I just want to disable a NetworkInterface.
我只想禁用NetworkInterface。
Does anyone know of a better way to do it? 有谁知道更好的方法吗? many thanks!
非常感谢!
尝试在具有管理员权限的情况下运行应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.