我想将注册表项及其子键导出为XML友好格式,而不是.REG。这仅用于报告目的,不会在以后导入。
在执行以下代码时,它为我提供了我想要的数据,而不是XML兼容。有关如何创建可以满足我需要的批处理文件/ vbs的任何建议吗?
REG QUERY hklm\software\microsoft\windows\currentversion\uninstall /s
答案 0 :(得分: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
答案 1 :(得分:0)
计划:
(如果您发布了一个体面的计划,我愿意帮助您实施。)