Windows 7 Registry\Script Issue

Hi
 
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?
JUP_ITAsked:
Who is Participating?
 
oBdACommented:
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
setlocal
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces" ^| find /i "\{"') do call :process "%%~a"
goto :eof

:process
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

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

:)
0
 
JUP_ITAuthor Commented:
add even
0
 
JUP_ITAuthor Commented:
Can it be done as a VBS script instead? I'm having UAC issues running this via SCCM.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.