Batch to preform regedits from parsed list

December 11, 2009 at 17:13:19
Specs: Windows XP
I am trying to get a script created that will assist to make a few registry edits when a syspreped XP builds in VMware.
We have some other batch files that run as the build and then normally we have to log in, edit a few files manually and execute them to make the reg edits.
The edits are for asset management, DHCP Client Identifier that we use for DHCP Reservations. There are some others but these are generic values to add and remove keys i can add later.

This is what i want my script to replace, because when building 20+ or so at a time, editing these files over and over is a PITA

I would like the script to look up its own hostname from a list (5000+ lines eventually) that has a corresponding DHCP Client Identifier assigned too it
e.g.

Computer0001,0xff00001
Computer0002,0xff00002
Computer0003,0xff00003
etc..

It would then use these 2 values in the reg edits

Asset
HKLM\Software\assetmgt\postbuild\ ComputerName = hostname

DHCP Client ID
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{NICGUID}\ DhcpClientIdentifier = hexvalue

The DCHP Client ID regedit i saw a small issue, we have various different build images that use different Network card drivers with different GUID and new NICs (GUID) in future, so it would need a little logic to know the right subkey and then use this GUID number as the correct subkey to enter the value

e.g.
..\Interfaces\{0609592C-27EF-4DDD-8905-750A74C6BDB8}\
..\Interfaces\{0731C122-5149-4770-B35F-3F2D4032D112}\
..\Interfaces\{F1FBE61A-0F82-41A9-A5E4-3162321CFB61}\

Once i have this script, we can add this into the run once and it will complete automatically and not have to manually edit to add these reg edits.

i looked around to try and work out how i could do this from other post ont he forum and my "skills" are virtually none excitant and i tried this

type data.csv|find "%computername%" > value.txt

for /f "tokens=1-2 delims=," %%a in (value.txt) do call :echo %%a %%b

:echo %%a %%b
@echo off
echo %1
echo %2

was just to see if i could get them to output seperately so i could use the values, but then i thought about the NIC GUID and was stumped

If any of you guys could assist i would be very grateful.


See More: Batch to preform regedits from parsed list

Report •


#1
December 11, 2009 at 22:15:58
hey, novice-alert! (me)
i'm assuming that this:
{NICGUID}
is a symbol for (something like) this:
{0609592C-27EF-4DDD-8905-750A74C6BDB8}\
or is it an actual keyname?
since i'm really inexperienced, unless you get some professional assistance meantime, can you post output:
reg query "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" /s >> forum.out
?
I can see the data in my registry, but mine is a client already built. I (being inexp) don't know what your server registry has... (edit the output for security, just need the "gist")

Report •

#2
December 12, 2009 at 04:57:00
Your correct the {NICGUID} is the long referance, i put some examples in my post with the first HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters cut off leaving ..\interface\{NICGUID}.
The builds are XP Pro builds and initially runs the scripts with a local administrator account during the initial setup and adding to the domain.

This is the output of "reg query "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" /s >> forum.out" This is just from one of my XP VM i have running at home, will be more or less the same

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{0609592C-27EF-4DDD-8905-750A74C6BDB8}
UseZeroBroadcast REG_DWORD 0x0
EnableDHCP REG_DWORD 0x0
IPAddress REG_MULTI_SZ 0.0.0.0\0\0
SubnetMask REG_MULTI_SZ 0.0.0.0\0\0
DefaultGateway REG_MULTI_SZ \0
EnableDeadGWDetect REG_DWORD 0x1
DontAddDefaultGateway REG_DWORD 0x0

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{0731C122-5149-4770-B35F-3F2D4032D112}
UseZeroBroadcast REG_DWORD 0x0
EnableDeadGWDetect REG_DWORD 0x1
EnableDHCP REG_DWORD 0x1
IPAddress REG_MULTI_SZ 0.0.0.0\0\0
SubnetMask REG_MULTI_SZ 0.0.0.0\0\0
DefaultGateway REG_MULTI_SZ \0
DefaultGatewayMetric REG_MULTI_SZ \0
NameServer REG_SZ
Domain REG_SZ
RegistrationEnabled REG_DWORD 0x1
RegisterAdapterName REG_DWORD 0x0
TCPAllowedPorts REG_MULTI_SZ 0\0\0
UDPAllowedPorts REG_MULTI_SZ 0\0\0
RawIPAllowedProtocols REG_MULTI_SZ 0\0\0
NTEContextList REG_MULTI_SZ 0x00000002\0\0
DhcpClassIdBin REG_BINARY
DhcpServer REG_SZ 192.168.245.254
Lease REG_DWORD 0x708
LeaseObtainedTime REG_DWORD 0x4b22eda8
T1 REG_DWORD 0x4b22f12c
T2 REG_DWORD 0x4b22f3cf
LeaseTerminatesTime REG_DWORD 0x4b22f4b0
IPAutoconfigurationAddress REG_SZ 0.0.0.0
IPAutoconfigurationMask REG_SZ 255.255.0.0
IPAutoconfigurationSeed REG_DWORD 0x0
AddressType REG_DWORD 0x0
IsServerNapAware REG_DWORD 0x0
DhcpIPAddress REG_SZ 192.168.245.134
DhcpSubnetMask REG_SZ 255.255.255.0
DhcpRetryTime REG_DWORD 0x384
DhcpRetryStatus REG_DWORD 0x0
DhcpNameServer REG_SZ 192.168.245.2
DhcpDefaultGateway REG_MULTI_SZ 192.168.245.2\0\0
DhcpDomain REG_SZ localdomain
DhcpSubnetMaskOpt REG_MULTI_SZ 255.255.255.0\0\0

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{F1FBE61A-0F82-41A9-A5E4-3162321CFB61}
UseZeroBroadcast REG_DWORD 0x0
EnableDHCP REG_DWORD 0x0
IPAddress REG_MULTI_SZ 0.0.0.0\0\0
SubnetMask REG_MULTI_SZ 0.0.0.0\0\0
DefaultGateway REG_MULTI_SZ \0
EnableDeadGWDetect REG_DWORD 0x1
DontAddDefaultGateway REG_DWORD 0x0

The actual Keyname that i need to add is

Value Name: DhcpClientIdentifier
Value Type: REG_DWORD
Value Range: 0x0 - 0xFFFFFFFF

the value range being the parsed value from the hostname/clientID list


Report •

#3
December 12, 2009 at 14:11:50
ok, one more question: what is the best criterion for obtaining the one you want? (i would assume the keywords
"dhcp" beginning any one of the following lines:)
DhcpServer REG_SZ 192.168.245.254
DhcpIPAddress REG_SZ 192.168.245.134
DhcpSubnetMask REG_SZ 255.255.255.0
DhcpRetryTime REG_DWORD 0x384
DhcpRetryStatus REG_DWORD 0x0
DhcpNameServer REG_SZ 192.168.245.2
DhcpDefaultGateway REG_MULTI_SZ 192.168.245.2\0\0

i went with that assumption...
here's the opening gambit:

@echo off && setlocal enabledelayedexpansion
for /f %%a in ('hostname') do set host=%%a
for /f "tokens=1-2 delims=," %%a in (biglist) do (
set hx=%%b
if "%%a" equ "!host!" goto BBB
)
echo host !host! not in master list, cant continue, aborting
goto :EOF
:BBB
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" /s > interx.tmp
for /f "tokens=1* delims={" %%a in (interx.tmp) do (
set test=%%b
if "!test!" neq "" (
set key=%%a{%%b
) else (
set test=%%a
set test=!test:~4,4!
if /i "!test!" equ "dhcp" (
call :regadd
goto :EOF)
)
)
::call build.bat
goto :EOF
:regadd
echo reg add "!key!" /v DhcpClientIdentifier /t REG_DWORD /d !hx! >> build.bat

(edited this post)


Report •

Related Solutions

#4
December 14, 2009 at 02:52:46
Thank you nbrane, I shall give your script a test run today with some builds and see how it handles.

I was thinking the EnableDHCP 0x1 for the active card, but DHCP values are as good as that.

Just reading thought the end part of the script, is this script ment to execute the build.bat or do i need to add another runonce entry to run the build.bat?


Report •


Ask Question