我想将注册表项及其子项导出为 XML 友好格式,而不是 .REG。这将仅用于报告目的,不用于以后导入。
执行以下代码时,它给了我想要的数据,只是不兼容 XML。关于如何创建可以满足我需要的批处理文件/vbs 的任何建议?
REG QUERY hklm\software\microsoft\windows\currentversion\uninstall /s
我想将注册表项及其子项导出为 XML 友好格式,而不是 .REG。这将仅用于报告目的,不用于以后导入。
执行以下代码时,它给了我想要的数据,只是不兼容 XML。关于如何创建可以满足我需要的批处理文件/vbs 的任何建议?
REG QUERY hklm\software\microsoft\windows\currentversion\uninstall /s
我最终自己解决了这个问题。我使用 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
一个计划:
(如果您发布了一个不错的计划,我愿意帮助您实施。)