5

I want to change with simple click (using a batch file) the MAC address of my wireless device. How I'll accomplish this? It needs to choose a random MAC address.

0

6 Answers 6

5

I am not sure if this is completely correct but it would be something like:

In a .reg file

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0009]
"NetworkAddress"="000011112222"

The 0009 would have to change to match the address you your adapter.

4
  • It changes the MAC address but I guess I have a bug social.technet.microsoft.com/Forums/en-US/w7itpronetworking/…
    – ilhan
    Commented Jan 8, 2012 at 18:59
  • @George: hidden in the middle of that long thread is the observation that it works provided you choose a properly constructed address, i.e., the low two bits of the first octet must be 10 as per en.wikipedia.org/wiki/MAC_address - is this the case for you? Commented Jan 10, 2012 at 1:31
  • @George: also note that changing the MAC works for me (even for improper addresses) and MS weren't able to reproduce the problem, so the issue is probably specific to a certain brand of network adapter. (Or perhaps all wireless adapters? I don't have one handy to play with.) Commented Jan 10, 2012 at 1:33
  • Since this (and all other registry-based solutions) but changes a registry value rather than call some API, I guess the change isn't applied till reboot of something. Commented Oct 14, 2015 at 22:44
4

There is a changeMac.bat file.

@echo off
netsh interface set interface "Local Area Connection" disable
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 /v NetworkAddress /d 002622D90EFC /f
netsh interface set interface "Local Area Connection" enable
echo Ok, enjoy it :)

There are three place you may need change: Local Area Connection, 0007, 002622D90EFC. Note: you must open regedit to find out what you should change the 0007 argument to. The Mac address has some rules: the second bit must be one of these numbers: 0 2 6 A E.

There is a recoverMac.bat that you may need.

@echo off
netsh interface set interface "Local Area Connection" disable
reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007 /v NetworkAddress /f
netsh interface set interface "Local Area Connection" enable
echo Ok,enjoy it :)
4

Run next command from batch file:

reg add HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0001 /v NetworkAddress /d 0123456789AB

Replace 0001 with your interface number and 0123456789AB with desired network addres.

1
  • It doesn't change the MAC address.
    – ilhan
    Commented Jan 8, 2012 at 18:58
3

Here is the definite batch file for changing MAC address on Windows 7: Like the (misleading) title of this question, it's missing the random part (left as an exercise to replace set /p with a call to a generator label). Handy now, with all this Denial-of-service-ing comeback...

:: Change MAC script by bobdynlan, release 1
:: For each network adapter it will list RegPath, GUID, Name, previous modified MAC if exists
:: Then you can input new MAC, clear previous MAC by inputting 0 or skip by pressing [Enter]
:: You can paste directly from ipconfig or wireshark because : < > { } [ ] - ( ) . will be filtered out
:: Note that for wireless in Win7 standard drivers has to start with 02... 06... 0A... 0E...
@ECHO OFF &SET /A RLINE=1 &SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F "tokens=3*" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" /S^|FINDSTR /I /L "REG_SZ"') DO (
SET /A RLINE+=1 &SET /A PARITY=!RLINE!^%%2
IF !PARITY! EQU 0 (SET "ADAPTERGUID=%%I") ELSE (
SET "ADAPTERNAME=%%I %%J"
FOR /F %%A IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}" /F "!ADAPTERGUID!" /D /E /S ^|FINDSTR /I /L /V "Linkage"^|FINDSTR /I /L "\\Class\\"') DO SET "REGPATH=%%A"
CLS &echo       Change MAC script by bobdynlan, release 1 &echo. &echo     RegPath = !REGPATH!  &echo     GUID = !ADAPTERGUID!  &echo     Adapter name = !ADAPTERNAME!
REG QUERY "!REGPATH!" /V "NetworkAddress" 2>&1 |FINDSTR /I /L "NetworkAddress"
SET "CHANGEMAC=" &SET "RESETMAC="
echo. &echo  Enter MAC address for this adapter [0 to reset it] or press [Enter] to skip: &SET /P "CHANGEMAC="
IF "!CHANGEMAC!"=="0" (SET "RESETMAC=Y" &SET "CHANGEMAC=") ELSE SET "RESETMAC="
IF DEFINED CHANGEMAC SET "CHANGEMAC=!CHANGEMAC: =!" &FOR %%I IN (: ^< ^> { } [ ] - ^( ^) .) DO SET "CHANGEMAC=!CHANGEMAC:%%I=!"
IF DEFINED CHANGEMAC REG ADD "!REGPATH!" /F /V NetworkAddress /T REG_SZ /D !CHANGEMAC! >nul 2>&1
IF DEFINED RESETMAC REG DELETE "!REGPATH!" /F /V NetworkAddress >nul 2>&1
))
IF DEFINED CHANGEMAC FOR /F "tokens=2,4*" %%I IN ('netsh interface show interface^|FINDSTR /I /L "Enabled"') DO (
netsh interface set interface %%J DISABLED
netsh interface set interface %%J ENABLED
)

ChangeMAC.bat

This batch script better formatted and all executables referenced with their fully qualified file names and other small changes resulting in same execution behavior as the more compact batch file above written by Bob Dynlan:

:: Change MAC script by bobdynlan, release 1
:: For each network adapter it will list RegPath, GUID, Name, previous modified MAC if exists
:: Then you can input new MAC, clear previous MAC by inputting 0 or skip by pressing [Enter]
:: You can paste directly from ipconfig or wireshark because : < > { } [ ] - ( ) . will be filtered out
:: Note that for wireless in Win7 standard drivers has to start with 02... 06... 0A... 0E...
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
SET "RLINE=1"
FOR /F "tokens=3*" %%I IN ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" /S ^| %SystemRoot%\System32\findstr.exe /I /L "REG_SZ"') DO (
    SET /A RLINE+=1
    SET /A PARITY=RLINE %% 2
    if !PARITY! EQU 0 (
        SET "ADAPTERGUID=%%I"
    ) ELSE (
        SET "ADAPTERNAME=%%I %%J"
        FOR /F %%J IN ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}" /F "!ADAPTERGUID!" /D /E /S ^|FINDSTR /I /L /V "Linkage" ^| %SystemRoot%\System32\findstr.exe /I /L "\\Class\\"') DO SET "REGPATH=%%J"
        CLS
        ECHO Change MAC script by bobdynlan, release 1
        ECHO(
        ECHO     RegPath = !REGPATH!
        ECHO     GUID = !ADAPTERGUID!
        ECHO     Adapter name = !ADAPTERNAME!
        %SystemRoot%\System32\reg.exe QUERY "!REGPATH!" /V "NetworkAddress" 2>&1 | %SystemRoot%\System32\findstr.exe /I /L "NetworkAddress"
        SET "CHANGEMAC="
        SET "RESETMAC="
        ECHO(
        ECHO Enter MAC address for this adapter [0 to reset it] or press [Enter] to skip:
        SET /P "CHANGEMAC="
        IF "!CHANGEMAC!" == "0" (
            SET "RESETMAC=Y"
            SET "CHANGEMAC="
        ) ELSE SET "RESETMAC="
        IF DEFINED CHANGEMAC (
            SET "CHANGEMAC=!CHANGEMAC: =!"
            FOR %%K IN (: ^< ^> { } [ ] - ^( ^) .) DO SET "CHANGEMAC=!CHANGEMAC:%%K=!"
        )
        IF DEFINED CHANGEMAC %SystemRoot%\System32\reg.exe ADD "!REGPATH!" /F /V NetworkAddress /T REG_SZ /D !CHANGEMAC! >nul 2>&1
        IF DEFINED RESETMAC %SystemRoot%\System32\reg.exe DELETE "!REGPATH!" /F /V NetworkAddress >nul 2>&1
    )
)
IF DEFINED CHANGEMAC FOR /F "tokens=2,4*" %%I IN ('%SystemRoot%\System32\netsh.exe interface show interface ^| %SystemRoot%\System32\findstr.exe /I /L "Enabled"') DO (
    %SystemRoot%\System32\netsh.exe interface set interface %%J DISABLED
    %SystemRoot%\System32\netsh.exe interface set interface %%J ENABLED
)
ENDLOCAL
2

you can use Technitium MAC Address changer command line to do it. Only you need to have it installed on the target machine.

0
  1. batch script yourself a cmd line regedit.
  2. Change the registry key value, like link here: http://www.windowsreference.com/networking/how-to-change-mac-address-in-windows-registry/

Not the answer you're looking for? Browse other questions tagged or ask your own question.