Question

Have seen - Assigning newline character to a variable in a batch script

I am wanting to take a REG_MULTI_SZ and split to multiple lines..

For example, we have:

if %PROCESSOR_ARCHITECTURE% == AMD64 SET ApacheKey="HKLM\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat6\Parameters\Java"
if NOT %PROCESSOR_ARCHITECTURE% == AMD64 SET ApacheKey="HKLM\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6\Parameters\Java"

POWERSHELL "Get-ItemProperty 'HKLM:%ApacheKey%' |select -ExpandProperty Options" >> somelog.txt

Thanks to the response below and the post found at - How to read multi line multi string registry entries in PowerShell? as this is now working!

Please note: I cannot use vbs (well I could) but would rather not as I have to codesign my scripts.

Can break out the "\0" delimiters. The issue that I have right now is that I type in echo %SETTINGS% from the command-line and I can see the new lines.. Probably going to have to PIPE the original variable to a text file. Read in (type) the file and if the "\0" is found to echo. which should write the file properly.

The original log shows:

-Dcatalina.base=C:\tomcat\0-Dcatalina.home=C:\tomcat\0-Djava.endorsed.dirs=C:\tomcat\endorsed\0-Djava.io.tmpdir=C:\tomcat\temp\0-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager\0-Djava.util.logging.config.file=C:\tomcat\conf\logging.properties\0-Dcom.sun.management.jmxremote\0-Dcom.sun.management.jmxremote.port=1092\0-Dcom.sun.management.jmxremote.ssl=false\0-Dcom.sun.management.jmxremote.authenticate=false\0-XX:MaxPermSize=256m\0-Xmx1024m\0-Xms1024m\0-Xverify:none\0-XX:+UseConcMarkSweepGC\0-XX:+UseParNewGC\0-XX:MinHeapFreeRatio=40\0-XX:MaxHeapFreeRatio=60\0-XX:MaxGCPauseMillis=200 

What I want it to show is:

-Dcatalina.base=C:\tomcat
-Dcatalina.home=C:\tomcat
-Djava.endorsed.dirs=C:\tomcat\endorsed
-Djava.io.tmpdir=C:\tomcat\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\tomcat\conf\logging.properties
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1092
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-XX:MaxPermSize=256m
-Xmx1024m
-Xms1024m
-Xverify:none
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:MinHeapFreeRatio=40
-XX:MaxHeapFreeRatio=60
-XX:MaxGCPauseMillis=200 
Was it helpful?

Solution

It can be simple using Vbscript working with your batch script:

:: Create readMulti.vbs
(
echo/Const HKEY_LOCAL_MACHINE = ^&H80000002
echo/strComputer = "."
echo/Set oReg=GetObject^("winmgmts:{impersonationLevel=impersonate}!\\" ^& _ 
echo/    strComputer ^& "\root\default:StdRegProv"^)
echo/strKeyPath = "SOFTWARE\Apache Software Foundation\Procrun 2.0\tomcat6\Parameters\Java"
echo/strValueName = "Options"
echo/oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
echo/    strValueName,arrValues
echo/For Each strValue In arrValues
echo/    Wscript.Echo  strValue
echo/Next)>readMulti.vbs
for /f "tokens=*" %%a in ('cscript //nologo readMulti.vbs') do (echo/%%a>>log.txt)
del readMulti.vbs
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top