How to Change the MAC Address in a Batch Script
A MAC (Media Access Control) address is the unique hardware identifier for a network adapter. While this address is permanently "burned into" the hardware, most network drivers in Windows allow you to override it with a custom value, a process known as "MAC spoofing." This is an advanced technique used for network testing, to bypass MAC-based access control on certain networks, or to enhance privacy.
This guide will teach you the standard and most reliable method for programmatically changing your MAC address by modifying a specific value in the Windows Registry. You will learn how to identify your network adapter, how to use the REG command to set the new address, and the critical final step of disabling and re-enabling the adapter to apply the change.
CRITICAL WARNING: This is an advanced networking operation. Changing your MAC address can cause you to lose your network connection. An incorrectly formatted MAC address can disable your network adapter until the change is reverted. Always note your original MAC address before you begin. This script must be run with full administrator privileges.
The Core Method: Modifying the NetworkAddress Registry Key
Windows does not have a simple command like SET MAC "New Address". Instead, this is controlled through a specific registry value for each network adapter. The process is:
- Find the unique GUID (Globally Unique Identifier) for the network adapter you want to change.
- Navigate to its registry key.
- Create or modify a string value named
NetworkAddress. - Set the value of
NetworkAddressto your desired new MAC address (as a 12-digit string with no hyphens or colons). - Disable and then re-enable the network adapter to force it to read the new registry setting.
Step 1: Finding Your Network Adapter's GUID
First, you need to identify the correct adapter. The getmac command is useful, but the most direct way to get the GUID is from the registry itself by looking at the list of network interfaces.
The Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}
This key contains numbered subkeys (0000, 0001, 0002, etc.), each representing a network adapter. You need to look inside each one for the DriverDesc value to find the one you want (e.g., "Intel(R) Wi-Fi 6 AX201").
Step 2: Getting Your Current MAC Address
Before you change anything, you must know your original, physical MAC address so you can revert the change if something goes wrong. The getmac command is the easiest way to do this.
getmac /V
Step 3: Setting the New MAC Address in the Registry
Once you have identified the correct subkey for your adapter (e.g., 0001), you can use the REG ADD command to set the new value.
Syntax: REG ADD "HKLM\...\<Subkey>" /v NetworkAddress /t REG_SZ /d "NewMacAddress" /f
/v NetworkAddress: The value name to add/modify./t REG_SZ: The type of the value (a string)./d "NewMacAddress": The data for the value. This must be a 12-digit hexadecimal string with no hyphens or colons (e.g.,001A2B3C4D5F)./f: Forces the overwrite without prompting.
Step 4: Restarting the Network Adapter to Apply the Change
The change in the registry will not take effect until the network adapter is restarted. You can do this from a script using the netsh command.
The Commands:
netsh interface set interface name="Wi-Fi" admin=disablednetsh interface set interface name="Wi-Fi" admin=enabled
You must use the correct interface name (e.g., "Wi-Fi", "Ethernet"). You can get a list of names with netsh interface show interface.
Example: A Full Script to Automate the Process
This script provides a complete, reusable template for changing a MAC address. You must manually find the DriverDesc and the registry subkey for your target adapter first.
@ECHO OFF
SETLOCAL
REM This script MUST be run as an Administrator.
REM --- (MANUAL) CONFIGURATION ---
REM Find these values for your adapter and set them here.
SET "AdapterName=Wi-Fi"
SET "AdapterRegKey=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0001"
SET "NewMacAddress=001A2B3C4D5F"
ECHO --- MAC Address Changer ---
ECHO WARNING: This will temporarily disconnect your network.
ECHO Adapter: %AdapterName%
ECHO New MAC: %NewMacAddress%
ECHO.
PAUSE
ECHO.
ECHO Step 1: Setting the NetworkAddress value in the registry...
REG ADD "%AdapterRegKey%" /v NetworkAddress /t REG_SZ /d "%NewMacAddress%" /f
IF %ERRORLEVEL% NEQ 0 (ECHO [ERROR] Failed to write to registry. & GOTO :End)
ECHO.
ECHO Step 2: Restarting the network adapter to apply changes...
ECHO Disabling %AdapterName%...
netsh interface set interface name="%AdapterName%" admin=disabled
TIMEOUT /T 3 > NUL
ECHO Enabling %AdapterName%...
netsh interface set interface name="%AdapterName%" admin=enabled
TIMEOUT /T 5 > NUL
ECHO.
ECHO --- Operation Complete ---
ECHO Verifying the new MAC address (this may take a moment)...
getmac /V
:End
ENDLOCAL
To revert the change, you can either delete the NetworkAddress value from the registry (REG DELETE ...) or set it to an empty string, and then restart the adapter again.
Conclusion
Changing a MAC address from a batch script is an advanced operation that requires direct manipulation of the Windows Registry.
The process is a clear, multi-step sequence:
- Identify the correct network adapter and its registry key.
- Use
REG ADDto set theNetworkAddressvalue to a 12-digit hex string (no hyphens). - Use
netsh interface set interfaceto disable and then re-enable the adapter.
Due to the risks involved, this should only be performed after making a full backup and recording your original MAC address. For most standard network tasks, changing the MAC address is not necessary, but for those specific situations that require it, this method provides complete programmatic control.