Discussion:
Append to a Registry Value using reg.exe
(too old to reply)
Andy MacRae
2004-10-08 09:38:01 UTC
Permalink
Hi,

I am writing a script to update an annoying package that our company
is forced to use.

One of the things this script must do is to update the System Path
registry key for the Environmental variables.

It needs to append to the end of it but leave the rest of the path
alone. I need to roll this out to 400 machines, of which most have
different path variables so I cannot just blank it and insert a new
one with all the usual stuff + the bit I want to put in.

Can reg.exe append to the end of the
hklm\system\currentcontrolset\control\session manager\environment\path
value? Or will I need to use a VBS script or something?

Cheers
Andy
Ted Davis
2004-10-08 13:59:59 UTC
Permalink
Post by Andy MacRae
Hi,
I am writing a script to update an annoying package that our company
is forced to use.
One of the things this script must do is to update the System Path
registry key for the Environmental variables.
It needs to append to the end of it but leave the rest of the path
alone. I need to roll this out to 400 machines, of which most have
different path variables so I cannot just blank it and insert a new
one with all the usual stuff + the bit I want to put in.
Can reg.exe append to the end of the
hklm\system\currentcontrolset\control\session manager\environment\path
value? Or will I need to use a VBS script or something?
Use the standard method: read - modify - write.
You use reg to read what's there, then use any suitable tool to append
the new string. When done, use reg to write the modified string over
the old one. Appending in place would require that the file space
used by the value have enough additional free space to add the new
data - this is highly unlikely, so whatever is done will involve a
read-modify-write cycle of the registry file itself.


T.E.D. (***@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
Matthias Tacke
2004-10-08 15:47:17 UTC
Permalink
Post by Ted Davis
Post by Andy MacRae
Hi,
I am writing a script to update an annoying package that our company
is forced to use.
One of the things this script must do is to update the System Path
registry key for the Environmental variables.
It needs to append to the end of it but leave the rest of the path
alone. I need to roll this out to 400 machines, of which most have
different path variables so I cannot just blank it and insert a new
one with all the usual stuff + the bit I want to put in.
Can reg.exe append to the end of the
hklm\system\currentcontrolset\control\session manager\environment\path
value? Or will I need to use a VBS script or something?
Use the standard method: read - modify - write.
You use reg to read what's there, then use any suitable tool to append
the new string. When done, use reg to write the modified string over
the old one. Appending in place would require that the file space
used by the value have enough additional free space to add the new
data - this is highly unlikely, so whatever is done will involve a
read-modify-write cycle of the registry file itself.
Maybe something like this:

::
@echo off
setlocal
set "key=hklm\system\currentcontrolset\control\session manager\environment"
set val=PATH
set ApP=YourPath2Append
for /f "tokens=1-2,*" %%A in (
'Reg query "%key%" /v %val%^|findstr /I "%val% REG_"') do (
echo REG ADD "%key%" /v %val% /t %%B /d %%C%ApP%; /f
)

Untested. If output seems ok remove the echo.

HTH
--
Greetings
Matthias
Continue reading on narkive:
Loading...