簡體   English   中英

嘗試禁用NetworkInterface

[英]Trying to disable a NetworkInterface

我正在創建管理我的NetworkInterfaces的小工具。 我在網上尋找了一種禁用nic的方法。 我已經有一個實例。

    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();
    }

這些功能都不產生我想要的結果。(實際上,它們什么都不做)。 我只想禁用NetworkInterface。

有誰知道更好的方法嗎? 非常感謝!

嘗試在具有管理員權限的情況下運行應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM