Skip to main content

How to Disable or Enable a Network Adapter in Batch Script

Automating network configuration is a key task for system administrators and power users. You might need to disable a wireless adapter to ensure a machine only uses a wired connection, or you might need to "bounce" a problematic network card by disabling and then re-enabling it to resolve a connectivity issue. The standard command-line tool for managing network interfaces in Windows is the powerful netsh (Network Shell).

This guide will teach you how to use the netsh command to programmatically disable and enable network adapters from a batch script. You will learn the critical prerequisite of finding the adapter's exact name and the absolute requirement of running the script as an administrator.

The Core Command: netsh interface set interface

The netsh utility is a command-line scripting interface for configuring and monitoring a wide range of network services. To change the state of an adapter, we use the interface set interface context.

The syntax is: netsh interface set interface name="<AdapterName>" admin=<STATE>

  • name="<AdapterName>": The name of the network connection as seen by the system (e.g., "Ethernet", "Wi-Fi"). This name must be exact.
  • admin=<STATE>: The desired administrative state.
    • admin=DISABLED: Disables the adapter.
    • admin=ENABLED: Enables the adapter.
note

This command must be run with administrator privileges.

CRITICAL: Finding the Exact Network Adapter Name

Before you can disable or enable an adapter, you need to know its precise name. This is often different from the simple "Ethernet" you see in the GUI. The best way to find the correct name is to use another netsh command.

Command to List Interfaces: netsh interface show interface

This command will produce a table listing all network interfaces on your system. The string in the "Interface Name" column is the exact name you must use in your script.

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled Connected Dedicated Ethernet
Enabled Disconnected Dedicated Wi-Fi
note

In this example, the correct names are "Ethernet" and "Wi-Fi".

Example: Script to Disable a Network Adapter

This script disables the adapter named "Wi-Fi". It must be run from an elevated (Administrator) command prompt.

@ECHO OFF
SET "AdapterName=Wi-Fi"

ECHO --- Disabling Network Adapter ---
ECHO Target: "%AdapterName%"
ECHO.

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

IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] The adapter has been disabled.
) ELSE (
ECHO [FAILURE] The command failed. Are you running as an Administrator?
)

Example: Script to Enable a Network Adapter

This script re-enables the "Wi-Fi" adapter.

@ECHO OFF
SET "AdapterName=Wi-Fi"

ECHO --- Enabling Network Adapter ---
ECHO Target: "%AdapterName%"
ECHO.

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

IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] The adapter has been enabled.
) ELSE (
ECHO [FAILURE] The command failed. Are you running as an Administrator?
)

The Modern Alternative: Using PowerShell

For modern systems, PowerShell offers cmdlets with more readable names and is often the preferred tool for system administration.

  • To Disable: Disable-NetAdapter -Name "AdapterName"
  • To Enable: Enable-NetAdapter -Name "AdapterName"

You can call these easily from a batch script:

powershell -Command "Disable-NetAdapter -Name 'Wi-Fi' -Confirm:$false"
powershell -Command "Enable-NetAdapter -Name 'Wi-Fi' -Confirm:$false"

The -Confirm:$false switch is crucial for preventing an interactive confirmation prompt in your script.

Common Pitfalls and How to Solve Them

Problem: The Script is Not Run as Administrator

This is the number one reason for failure. Modifying the state of a network adapter is a privileged operation.

Exmaple of error message:

The requested operation requires elevation (Run as administrator).

Solution: The script must be run from an elevated command prompt. Right-click your .bat file or cmd.exe and select "Run as administrator." There is no workaround.

Problem: Using the Wrong Interface Name

If the name you provide doesn't exactly match the "Interface Name" from the netsh interface show interface list, the command will fail.

Exmaple of error message:

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

Solution: Always run netsh interface show interface first to get the exact, correct name. Be especially careful with default names like "Ethernet 2" or "Local Area Connection".

Practical Example: A "Network Reset" Script

This is a common troubleshooting technique. The script disables a specific network adapter, waits a few seconds, and then re-enables it.

@ECHO OFF
SETLOCAL
TITLE Network Adapter Reset Utility
REM This script must be run as an Administrator.

SET "AdapterToReset=Ethernet"

ECHO --- Network Adapter Reset ---
ECHO This will disable and then re-enable the '%AdapterToReset%' adapter.
ECHO.
PAUSE

ECHO Step 1: Disabling the adapter...
netsh interface set interface name="%AdapterToReset%" admin=DISABLED

ECHO.
ECHO Waiting for 5 seconds...
TIMEOUT /T 5 /NOBREAK > NUL

ECHO.
ECHO Step 2: Re-enabling the adapter...
netsh interface set interface name="%AdapterToReset%" admin=ENABLED

ECHO.
ECHO --- Reset complete ---
ENDLOCAL

Conclusion

The netsh command is the standard, built-in tool for managing network adapters from the command line, making it perfect for batch scripting.

Key takeaways for success:

  • You must run your script as an Administrator.
  • First, find the exact interface name using netsh interface show interface.
  • Use netsh interface set interface name="..." admin=DISABLED to disable.
  • Use netsh interface set interface name="..." admin=ENABLED to enable.
  • For modern scripts, calling the PowerShell cmdlets (Disable-NetAdapter, Enable-NetAdapter) is a clean and powerful alternative.