簡體   English   中英

從命令行啟用/禁用網絡連接

[英]Enable/disable network connection from command line

我知道在 Google 中存在大量的結果: results ,但我沒有在我的 Windows XP 機器上找到它。 我想從命令行禁用 LAN 連接。

>netsh interface set interface "Local Area Connection" DISABLED
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

>netsh interface set interface name="Local Area Connection" admin="disabled"
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

>netsh interface set interface name="Local Area Connection" admin=DISABLED
One or more essential parameters not specified
The syntax supplied for this command is not valid. Check help for the correct sy
ntax.

對於前兩個命令,您需要提升/管理員權限:

禁用 LAN 網絡連接

C:\> netsh interface set interface name="Local Area Connection" admin=disabled

啟用 LAN 網絡連接

C:\> netsh interface set interface name="Local Area Connection" admin=enabled

假設:您的接口被命名為“本地連接”,否則替換為正確的名稱。 使用netsh interface show interface查找名稱。

列出 Wifi 配置文件

C:\> netsh wlan show profiles

連接到 Wifi 配置文件

C:\> netsh wlan connect name="ProfileName"

您必須以提升的/管理員權限運行它。

(在 Windows 7 上,否則我會收到令人困惑的錯誤消息

An interface with this name is not registered with the router.

)

(我編輯了@yarish kumar 的回答以反映這一點。)

好吧,看來您需要從表中刪除配置文件。 IE

netsh LAN>刪除“LAN連接配置文件”

在此之前,您應該保存 LAN 的配置信息,以防您想將其添加回來,它將另存為 XML 文件,然后將其添加回來就行了

netsh LAN>ADD file-name="profile1.XML" interface="本地連接"

另請查看http://www.computerhope.com/netsh.htm以了解有關 netsh 命令的更多詳細信息

希望這可以幫助

C:\\WINDOWS\\system32>netsh interface 顯示界面

管理狀態狀態類型接口名稱

Enabled Connected Dedicated Ethernet 2 Enabled Disconnected Dedicated Ethernet Enabled Connected Dedicated Wi-Fi

C:\\WINDOWS\\system32>netsh interface set interface name="Ethernet" admin=啟用或禁用

w10 輸出這個..

  1. 以管理員身份啟動命令提示符。

  2. 要顯示包含“接口名稱”、“狀態”等的列表,請鍵入以下內容:

    netsh 界面 顯示界面

它會回聲應該是這樣的。

> netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        Local Area Connection
Disabled       Disconnected   Dedicated        Local Area Connection 4
  1. 現在,從列表中選擇一個“接口名稱”。 例如,如您所見,我的是“本地連接”

啟用選定的連接,請鍵入以下內容:

“%InterfaceName%”在哪里放置您的接口名稱。 注意:如果包含空格,請用雙引號 ["] 關閉“接口名稱”,例如我的:“本地連接”。

netsh interface set interface "%InterfaceName%" ENABLE

或者,如果不適合您,請嘗試下一個:

netsh interface set interface name="%InterfaceName%" admin=ENABLED

禁用選定的連接,請鍵入以下內容:

 netsh interface set interface "%InterfaceName%" DISABLE

或者,如果不適合您,請嘗試下一個:

netsh interface set interface name="%InterfaceName%" admin=DISABLED

提示:您可以通過雙擊“重新啟動 Connection.cmd”或“重新啟動 Connection.bat”來完成這項工作。 ;) 這可能是這樣的:

@echo off
mode con: cols=80 lines=27
title Connection Restart
color 1f
cls
echo  This program restarts Internet Connection adapter.
echo.
echo  List of network adapters (Internet adapters)
netsh interface show interface
echo ==========================================================================

:: Setting Interface Name
set InterfaceName=Local Area Connection

:Disadling adapter
echo. & echo
echo  RESTARTING "%InterfaceName%" adapter. WAIT...
netsh interface set interface "%InterfaceName%" disable
echo "%InterfaceName%" adapter disabled. Wait...
echo. & echo.==========
timeout /t 5 >nul

:Enabling adapter
netsh interface set interface "%InterfaceName%" enable
echo "%InterfaceName%" adapter Enabled. Wait...
echo. & echo.==========
echo  Procedure completed successfully

timeout /t 6 >nul
EXIT

請注意,您需要在此批次中替換以使其適合您的唯一內容是第 13 行中“接口名稱”的(確切)名稱。

例如,以粗體顯示的名稱: set InterfaceName= Local Area Connection

這一行(第 13 行)使該變量成為“%InterfaceName%”,因此您無需更改任何其他內容即可工作。 但如果你願意,你可以嘗試。

享受

暫無
暫無

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

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