Hi,sincos,
根据我的研究,你可以使用下面的代码来启用和禁用网络适配器。
ManagementClass processClass = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject item in processClass.GetInstances())
{
if (item["DeviceID"].ToString()=="1")
{
object[] obj = { };
item.InvokeMethod("Enable", obj);
item.InvokeMethod("Disable", obj);
break;
}
}
Console.WriteLine("success");
注意:这边首先需要确认哪些网络适配器已经连接了,只有连接的才能去启用和禁用,另外这段代码需要以管理员权限来运行。
希望这会帮到你。
Best Regards,
Jack
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.