2013-02-28 53 views
0

我想将注册表项及其子项导出为XML友好格式,而不是.REG。这将仅用于报告目的,而不是稍后导入。将注册表树导出为XML

当执行下面的代码时,它给了我想要的数据,只是不兼容XML。任何关于如何创建一个批处理文件/ vbs的建议,将做我所需要的?

REG QUERY hklm\software\microsoft\windows\currentversion\uninstall /s 

回答

1

我终于明白了我自己的想法。我使用for循环来枚举每个注册表项,然后使用echo命令将信息输出到CSV文件和XML文档中。对于那些可能想要尝试去做的人来说,这是一个例子。 (不是我的确切代码)

Echo ^<?xml version="1.0" encoding="ISO-8859-1"?^> >>myxml.xml 
Echo ^<document^> >>myxml.xml 
Echo ^<Computer Name="%Computername%"^> >>myxml.xml 
Echo ^<Applications^> >>myxml.xml 

for /f "tokens=7 delims=\" %%a in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ^|findstr /v "KB1 KB2 KB3 KB4 KB5 KB6 KB7 KB8 KB9"') do ( 

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".displayVersion">version.txt 
for /f "tokens=3*" %%c in (version.txt) do echo %%c %%d>version1.txt 
if EXIST version1.txt set /p version=<version1.txt 

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".displayName">Name.txt 
for /f "tokens=3*" %%e in (Name.txt) do echo %%e %%f>Name1.txt 
if EXIST name1.txt Set /p name=<name1.txt 

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".InstallDate">InstallDate.txt 
for /f "tokens=3*" %%j in (Installdate.txt) do echo %%j %%k>InstallDate1.txt 
IF EXIST Installdate1.txt set /p installdate=<Installdate1.txt 


reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".UninstallString">UString.txt 
for /f "tokens=3*" %%l in (Ustring.txt) do echo %%l %%m>Ustring2.txt 
if exist Ustring2.txt type Ustring2.txt|findstr /v "&">Ustring1.txt 
IF EXIST Ustring1.txt set /p Ustring=<Ustring1.txt 

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".Publisher">Publisher.txt 
for /f "tokens=3*" %%n in (Publisher.txt) do echo %%n %%o>Publisher1.txt 
IF EXIST Publisher1.txt set /p Publisher=<Publisher1.txt 

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%a" |Findstr /i ".InstallLocation">Installloc.txt 
for /f "tokens=3*" %%v in (Installloc.txt) do echo %%v %%w>Installloc1.txt 
IF EXIST Installloc1.txt set /p Installloc=<Installloc1.txt 


if NOT defined installdate set installdate=N/A 
if NOT defined name set name=%%a 
if NOT defined version set version=N/A 
if NOT defined Ustring set Ustring=N/A 
if NOT defined Publisher set Publisher=N/A 
if NOT defined Installloc set Installloc=N/A 
echo !name:^&=!'!version!'!Publisher:^&=!'!Installdate!'!Installloc:^&=!'!UString! >>programlist.csv 
) 

::Now Creating XML from CSV 

for /f "tokens=1-6 delims='" %%p in (programlist.csv) DO (

echo ^<Product Name="%%p"^> >>myxml.xml 
echo  ^<Version^>%%q^</Version^> >>myxml.xml 
echo  ^<Publisher^>%%r^</Publisher^> >>myxml.xml 
echo  ^<Installdate^>%%s^</Installdate^> >>myxml.xml 
echo  ^<installLocation^>%%t^</installLocation^> >>myxml.xml 
echo  ^<UninstallString^>%%u^</UninstallString^> >>myxml.xml 

echo ^</Product^> >>myxml.xml 
) 

Echo ^</Applications^> >>myxml.xml 
echo ^</Computer^> >>myxml.xml 
0

一个计划:

  1. 开始写一个模式文件(XSD),让你去想节点/元素,属性和数据类型
  2. 使用递归目录学步车设计递归注册表助手(可能使用WMI);看Scriptomatic2用来WMI信息导出到XML
  3. 方法
  4. (再)阅读重点放在创建/克隆功能的XML文档,以拿出一个战略,把注册表信息到XML树

(如果你发布了一个体面的计划,我愿意帮助你实现。)