Windows 7 Registry\Script Issue

Posted on 2011-04-27
Last Modified: 2013-11-05
How can I query the registry for a key value, then use that value to create a DWORD in that key? Can I use a variable instead? Like '*'?

I'm trying to add an entry here 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{Dynamic GUID here}'. The problem is the GUID is different on every computer.  I then want to create the DWORD 'DhcpConnForceBroadcastFlag' with a value of '1' in the key.

Can anyone help?
Question by:JUP_IT
    LVL 82

    Accepted Solution

    Try the batch script below; it will scan all GUIDs and only add the value if DHCP is enabled for the adapter.
    The script is currently in test mode, it will only display the "reg add" command it would normally run.
    Remove the capitalized ECHO in line 14 to run it for real.
    @echo off
    for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces" ^| find /i "\{"') do call :process "%%~a"
    goto :eof
    set Interface=%~1
    echo Processing %Interface% ...
    reg query "%Interface%" /v "EnableDHCP" 2>NUL | find /i "0x1" >NUL
    if errorlevel 1 (
      echo ... ignored, DHCP disabled.
    ) else (
      echo ... adding value ...
      ECHO reg add "%Interface%" /v "DhcpConnForceBroadcastFlag" /d "1" /f

    Open in new window


    Author Comment

    Nice work, thanks. I just had to a /t REG_DWORD to create the correct value type.


    Author Comment

    add even

    Author Comment

    Can it be done as a VBS script instead? I'm having UAC issues running this via SCCM.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now