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

Batch file 使用批处理文件枚举注册表项,batch-file,registry,Batch File,Registry,我正在尝试查询已安装软件的安装位置。它的每个新版本都会按照以下模式在注册表中创建自己的密钥: HKLM\Software\MySoftware\<VERSION> 如何查询计算机上安装的最新版本的InstallDir @echo off setlocal enableDelayedExpansion regedit /e /s HKLM\Software\MySoftware C:\export.txt set version_candidate=000 for /f "toke

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

HKLM\Software\MySoftware\<VERSION>
如何查询计算机上安装的最新版本的
InstallDir

@echo off
setlocal enableDelayedExpansion
regedit /e /s HKLM\Software\MySoftware 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 HKLM\Software\MySoftware\version 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

这是一个猜测,因为我不知道您的注册表项是什么样子。

版本是什么样子的?普通数字?它有点和下划线吗?到目前为止只有数字,0.1.0和0.2.0
@echo off
setlocal enableDelayedExpansion
regedit /e /s HKLM\Software\MySoftware 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 HKLM\Software\MySoftware\version 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