我的系统是通过局域网连接的。
我需要关闭我的局域网连接
如何使用C#程序执行此操作
你能帮帮我吗??
发布于 2011-05-19 15:06:37
Public Shared Sub ToggleWirelessConnection()
For Each verb As Shell32.FolderItemVerb In WirelessConnectionFolderItem.Verbs
If verb.Name = "En&able" OrElse verb.Name = "Disa&ble" Then
verb.DoIt()
Exit For
End If
Next
Threading.Thread.Sleep(1000)
End Sub这是用VB编写的代码,它可以工作。
发布于 2011-05-17 17:52:54
因为我已经在SuperUser上回答了这个问题--只是在这里添加了这个,因为它应该只在SO上:
您可以从命令行禁用/启用NIC:
netsh interface set interface “Local Area Connection” disabled
netsh interface set interface “Local Area Connection” enabled将"Local Area Connection“替换为要禁用的网络接口的名称。
您可以使用如下代码从C#调用此函数:
启用
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();
}https://stackoverflow.com/questions/6026374
复制相似问题