Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

DevCon 命令列神器:一鍵啟用停用網卡,批次腳本自動化操作指南

編輯:Windows Vista 系統基礎知識

聰明人往往很懶,懶到多點幾下滑鼠就覺得渾身不舒服。對於啟用停用網卡,雖然在控制台網路設定裡就能搞定,但他們偏要用批次檔實現。微軟的 DevCon 工具正好滿足這需求,可從命令列啟用或停用網卡,以下是兩個批次檔範例:

@echo off
devcon disable *DEV_8136*
devcon enable *DEV_8136*
echo on

準備工作

  1. 先到微軟官網下載 DevCon 工具(若電腦已有則免下載,檔案在 Windows\System32 目錄下):
    https://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe
  2. 下載後放入 system32 目錄。
  3. 開啟命令提示字元(執行 cmd)。
  4. 輸入 devcon find pci\* 列出所有 PCI 裝置,例如:
    PCI\VEN_13F0&DEV_0201&SUBSYS_020113F0&REV_14\3&13C0B0C5&0&48: Sundance ST201 based PCI Fast Ethernet Adapter #3
  5. 記下第一個 & 和第二個 & 之間的裝置代碼,例如 DEV_0201。

批次腳本範例

devcon disable *DEV_0201*  // 停用此 PCI 裝置
devcon enable *DEV_0201*   // 啟用此 PCI 裝置

DevCon 詳細介紹

DevCon 是命令列實用工具,可取代裝置管理員。使用 DevCon 可啟用、停用、重啟、更新、刪除、查詢單一裝置或一組裝置,還能提供驅動程式開發者相關、但在裝置管理員看不到的資訊。支援 Windows 2000、XP、Server 2003、Vista、Win7,不支援 Win95/98/Me。

常用指令速查

  • devcon find *:列出本機所有裝置實例。
  • devcon find pci\*:列出所有 PCI 裝置。
  • devcon disable *msloop:停用硬體 ID 以 MSLOOP 結尾的所有裝置。
  • devcon enable '*MSLOOP:啟用硬體 ID 為 *MSLOOP 的所有裝置(單引號表嚴格比對)。
  • devcon remove @usb\*:刪除所有 USB 裝置。

硬體 ID 說明

執行 find pci\* 後輸出的每行「:」前即為硬體 ID,後為裝置名稱。例如:
PCI\VEN_10EC&DEV_8139&SUBSYS_813910EC&REV_10\3&13C0B0C5&0&58: Realtek RTL8139 Family PCI Fast Ethernet NIC

要停用網卡:devcon disable *DEV_8139*(前提是電腦有 devcon.exe)
要啟用:devcon enable *DEV_8139*

若指定 -r 且需重啟,處理完所有裝置後會無警告直接重啟。壓縮包含 32 位與 64 位兩個資料夾,分別對應 I386\DevCon.exe 與 Ia64\DevCon.exe。

Copyright © Windows教程網 All Rights Reserved