对于我的一些项目,我必须禁用我的连接5秒,然后再次启用它。
我现在该怎么做(这不是最佳解决方案,但我使用的是Windows VPN):
所以我基本上想知道一种断开连接的方法,比如连接到破损的VPN(没有Wi-Fi)。
在C#代码中。
这可能吗?
答案 0 :(得分:0)
选择a look:
使用netsh命令,您可以启用和禁用“本地连接”
interfaceName is “Local Area Connection”.
static void Enable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" enable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
static 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();
}