JSI Tip 0908. Append data to a registry <b>value</b>.


If you need to append data to an existing registry value, in batch, and you don't know the string that is currently set, JSIRVA.bat may be the solution. The usage syntax is:

JSIRVA RegPath RegType RegValue where:

 Parameter   M e a n i n g 
 RegPath   See the freeware REG.EXE, which is used in JSIRVA. Both JSIRVA and REG must be in your path. 
 RegType   REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ. Upper case is required. 
 RegValue   The String you wish to append. JSIRVA uses a ; as the seperator, so it should not be the first character of RegValue. Both ! and # are reserved and may not be present in the existing registry string or in RegValue. " may be used to enclose the string. If you want them as data, use ""

Note: JSIRVA returns environment variable RVA:
- set to none, if there is an error.
- set to RegType, if the command was successfull.

Examples:

To append jsiinc to ProxyOverride in the local registry:

JSIRVA "HKU\.Default\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride" REG_SZ jsiinc
The resultant registry value may look like:
microsoft;jsiinc

To append the Spooler service to the DependOnService value entries of the NetLogon service, on computer JSI005:

JSIRVA \\JSI005\HKLM\System\CurrentControlSet\Services\NetLogon\DependOnService REG_MULTI_ SZ Spooler

To append "This value has spaces" to HKCU\Software\JSIINC\Notes:

JSIRVA HKCU\Software\JSIINC\Notes REG_ SZ ""This value has a space""

JSIRVA.bat contains:

@echo off
set RVA=none
if "%3"

"" goto syntax if "%2"

"REG_SZ" goto ok1 if "%2"

"REG_MULTI_SZ" goto ok1 if "%2"

"REG_EXPAND_SZ" goto ok1 :syntax @echo Syntax: JSIRVA REGPATH TYPE VALUE set RVA=none set rp= set rt= set rv= set nv= set rw1= set rw2= goto end :ok1 set rp=%1 set rt=%2 set rv=##%3## set rv=%rv:##"=% set rv=%rv:"##=% set rv=%rv:##=% set nv= set RVA=begin for /f "Tokens=*" %%i in ('reg -Quiet -ListValue %1') do call :ok2 "%%i" if "%RVA%"

"none" goto syntax if not "%nv%"

"" set nv=%nv:!=;% if "%RVA%"

"REG_MULTI_SZ" goto m1 if not "%nv%"

"" goto m3 set rw1=%rv% goto m4 :m1 if "%nv%"

"" goto m2 set rw1=;%nv%;%rv% goto m4 :m2 set rw1=;%rv% goto m4 :m3 set rw1=%nv%;%rv% :m4 reg -Quiet -Set %rt% %rp%='%rw1%' set rp= set rt= set rv= set nv= set rw1= set rw2= set sp= goto end :ok2 set rw1=%1 If %rw1%

"<end>" goto end set rw1=%rw1:"=#% set rw1=%rw1:;=!% for /f "tokens=1*" %%j in ('@echo %rw1%') do call :ok3 %%j "%%k" if "%RVA%"

"none" goto syntax goto end :ok3 set rw2=%1 set rw2=%rw2:#=% if "%RVA%"

"REG_MULTI_SZ" goto more if "%rt%"

"%rw2%" goto ok4 set RVA=none goto end :ok4 set RVA=%rt% set nv= if %2

"#" goto end set rw2=%2 set rw2=%rw2:#"=% set rw2=%rw2:"=% set rw2=%rw2:##="% set rw2=%rw2:#="% set nv=%rw2% goto end :more set rw2=%2 set rw2=%rw2:#"=% set rw2=%rw2:"=% set rw2=%rw2:##="% set rw2=%rw2:#="% set nv=%nv%;%rw2% :end

TAGS: Windows 8
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish