Вы можете использовать цикл For
, чтобы сохранить результат команды в виде переменной:
powershell.exe
пример:
@Echo Off
Set "RegRoot=HKLM"
Set "RegKey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\myapp"
Set "RegVal=DisplayVersion"
Set "Version="
For /F %%A In (
'PowerShell -NoP -NoL "(GP '%RegRoot%:%RegKey%').%RegVal%" 2^>Nul'
) Do Set "Version=%%A"
If Not Defined Version Exit /B
Echo %Version%
Pause
reg.exe
пример:
@Echo Off
Set "RegRoot=HKLM"
Set "RegKey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\myapp"
Set "RegVal=DisplayVersion"
Set "Version="
For /F "Tokens=2*" %%A In ('Reg Query "%RegRoot%\%RegKey%" /V "%RegVal%" 2^>Nul'
) Do Set "Version=%%B"
If Not Defined Version Exit /B
Echo %Version%
Pause
WMIC.exe
пример:
@Echo Off
Set "RegRoot=&H80000002"
Set "RegKey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\myapp"
Set "RegVal=DisplayVersion"
Set "Version="
For /F Tokens^=2Delims^=^" %%A In ('WMIC Class StdRegProv
Call GetStringValue hDefKey^="%RegRoot%" sSubKeyName^="%RegKey%"
sValueName^="%RegVal%" 2^>Nul') Do Set "Version=%%A"
If Not Defined Version Exit /B
Echo %Version%
Pause