批量尝试从REG_MULTI_SZ值记录信息

时间:2014-03-26 16:29:58

标签: batch-file logging split registry

见过 - Assigning newline character to a variable in a batch script

我想要一个REG_MULTI_SZ并拆分成多行......

例如,我们有:

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

感谢以下回复和帖子 - How to read multi line multi string registry entries in PowerShell? 因为现在正在运作!

请注意:我不能使用vbs(我可以)但不愿意,因为我必须对脚本进行编码。

可以打破“\ 0”分隔符。我现在的问题是我从命令行键入echo%SETTINGS%,我可以看到新的行。可能需要将原始变量PIPE到文本文件。读入(键入)文件,如果发现“\ 0”回显。哪个应该正确写入文件。

原始日志显示:

-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 

我希望它展示的是:

-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 

1 个答案:

答案 0 :(得分:1)

使用Vbscript处理批处理脚本可能很简单:

:: 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