JSI Tip 0908. Append data to a registry value .
December 10, 1998
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 , 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.DefaultSoftwareMicrosoftWindowsCurrentVersionInternet SettingsProxyOverride" 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 \JSI005HKLMSystemCurrentControlSetServicesNetLogonDependOnService REG_MULTI_ SZ Spooler
To append "This value has spaces" to HKCUSoftwareJSIINCNotes:
JSIRVA HKCUSoftwareJSIINCNotes REG_ SZ ""This value has a space""
JSIRVA.bat contains:
@echo offset RVA=noneif "%3"
<21>
<a name="_goto_syntax_if_2_" id="_goto_syntax_if_2_">"" goto syntaxif "%2"</a>
"REG_SZ" goto ok1if "%2"
<a name="_REG_MULTI_SZ_goto_ok1_if_2_" id="_REG_MULTI_SZ_goto_ok1_if_2_">"REG_MULTI_SZ" goto ok1if "%2"</a>
"REG_EXPAND_SZ" goto ok1:syntax@echo Syntax: JSIRVA REGPATH TYPE VALUE set RVA=noneset rp=set rt=set rv=set nv=set rw1=set rw2=goto end:ok1set rp=%1set rt=%2set rv=##%3##set rv=%rv:##"=%set rv=%rv:"##=%set rv=%rv:##=%set nv=set RVA=beginfor /f "Tokens=*" %%i in ('reg -Quiet -ListValue %1') do call :ok2 "%%i"if "%RVA%"
<a name="_none_goto_syntax_if_not_nv_" id="_none_goto_syntax_if_not_nv_">"none" goto syntaxif not "%nv%"</a>
"" set nv=%nv:!=;%if "%RVA%"
<a name="_REG_MULTI_SZ_goto_m1_if_not_nv_" id="_REG_MULTI_SZ_goto_m1_if_not_nv_">"REG_MULTI_SZ" goto m1if not "%nv%"</a>
"" goto m3set rw1=%rv%goto m4:m1if "%nv%"
<a name="_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_" id="_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_">"" goto m2set rw1=;%nv%;%rv%goto m4:m2set rw1=;%rv%goto m4:m3set rw1=%nv%;%rv%:m4reg -Quiet -Set %rt% %rp%='%rw1%'set rp=set rt=set rv=set nv=set rw1=set rw2=set sp=goto end:ok2set rw1=%1If %rw1%</a>
"" goto endset rw1=%rw1:"=#%set rw1=%rw1:;=!%for /f "tokens=1*" %%j in ('@echo %rw1%') do call :ok3 %%j "%%k" if "%RVA%"
<a name="_none_goto_syntax_goto_end_ok3_set_rw2_1_set_rw2_rw2_#_if_RVA_" id="_none_goto_syntax_goto_end_ok3_set_rw2_1_set_rw2_rw2_#_if_RVA_">"none" goto syntaxgoto end:ok3set rw2=%1set rw2=%rw2:#=%if "%RVA%"</a>
"REG_MULTI_SZ" goto moreif "%rt%"
<a name="_rw2_goto_ok4_set_RVA_none_goto_end_ok4_set_RVA_rt_set_nv_if_2" id="_rw2_goto_ok4_set_RVA_none_goto_end_ok4_set_RVA_rt_set_nv_if_2">"%rw2%" goto ok4set RVA=nonegoto end:ok4set RVA=%rt%set nv=if %2</a>
"#" goto endset rw2=%2set rw2=%rw2:#"=%set rw2=%rw2:"=%set rw2=%rw2:##="%set rw2=%rw2:#="%set nv=%rw2%goto end:moreset rw2=%2set rw2=%rw2:#"=%set rw2=%rw2:"=%set rw2=%rw2:##="%set rw2=%rw2:#="%set nv=%nv%;%rw2%:end
About the Author
You May Also Like