I'm creating little tool to manage my NetworkInterfaces. I've looked all over the web for a way to disable a 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.
Does anyone know of a better way to do it? many thanks!
尝试在具有管理员权限的情况下运行应用程序
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.