使用批处理文件枚举注册表项



我正在查询已安装软件的安装位置。它的每个新版本都按照以下模式在注册表中创建自己的密钥:

HKLMSoftwareMySoftware<VERSION>

示例:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMySoftware.2.0]
"InstallDir"="C:\Program Files\MySoftware"

如何查询计算机上安装的最新版本的InstallDir

@echo off
setlocal enableDelayedExpansion
regedit /e /s HKLMSoftwareMySoftware C:export.txt
set version_candidate=000
for /f "tokens=4,5,6 delims=." %%a in ('type C:export.txt ^|findstr /r "[0-9].[0-9].[0-9]"') do (
    if %%a%%b%%c gtr !version_candidate! set version_candidate=%%a%%b%%c
)
set version=%version_candidate:~0,1%.%version_candidate:~1,1%.%version_candidate:~2,1%
regedit /e /s HKLMSoftwareMySoftwareversion C:export2.txt
for /f "tokens=2 delims==" %%a do ('type C:export2.txt ^|find /i "InstallDir"') do (
    set i_dir=%%a
)
echo %i_dir%
endlocal

只是猜测,因为我不知道你的注册表项是什么样子的。

最新更新