Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 禁用局域网连接_C# 4.0 - Fatal编程技术网

C# 4.0 禁用局域网连接

C# 4.0 禁用局域网连接,c#-4.0,C# 4.0,我的系统通过局域网连接 我需要禁用我的局域网连接 如何使用C#程序实现这一点 你能帮我吗???因为我已经回答了这个问题-只需在这里添加这个,因为它本应该只打开了,所以: 您可以从命令行禁用/启用NIC: netsh interface set interface “Local Area Connection” disabled netsh interface set interface “Local Area Connection” enabled 将“局域网连接”替换为要禁用的网络接口的名称

我的系统通过局域网连接

我需要禁用我的局域网连接

如何使用C#程序实现这一点


你能帮我吗???

因为我已经回答了这个问题-只需在这里添加这个,因为它本应该只打开了,所以:

您可以从命令行禁用/启用NIC:

netsh interface set interface “Local Area Connection” disabled
netsh interface set interface “Local Area Connection” enabled
将“局域网连接”替换为要禁用的网络接口的名称

您可以从C#使用以下类似的方法调用此函数:

使可能 使残废
这是VB中的代码,它可以工作。

这个问题是一样的:如果不调用windows API,就不能禁用LAN连接。@icktoofay:我在LAN中连接了三个系统。我需要在需要时断开特定系统的internet连接,如果禁用LAN连接,我想我可以断开internet连接。你能帮我吗???@bleepzter:我怎么能调用Windows API,我是C#的新手,你能帮我吗?这里有两次被问到,超级用户也有两次被问到。在注意到这一点之前,我在SU上发布了我的答案,否则我就不会看两遍了。谢谢jaymz,我是新来的,这就是为什么!!我应该禁用LAN,我如何才能找到interfacename。。是不是像“\\admin\root\cimv2:Win32\U NetworkAdapterConfiguration.Index=1”我不明白,你能帮我一下吗。我正在使用windows XP。我需要断开LAN电缆。禁用/启用接口的代码在那里。你还不明白什么?如果你需要回答更多的问题,可以问一个新问题,清楚地解释你要问的是什么。谢谢jayamz,我找到了一个VB程序来解决我的难题,如果我开始一个新问题,他们就会结束它。。不知道为什么?
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();
}
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