从批处理文件查询注册表时,我可以查询数据吗?

时间:2013-10-25 04:25:30

标签: batch-file registry

我有以下查询 -

@ECHO OFF
REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\10.0" /v AppPath
PAUSE

这将返回条目的名称,类型和数据,如下所示 -

HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\10.0
    AppPath    REG_SZ    C:\Program Files (x86)\Microsoft Games\Microsoft Flight Simulator X\

Press any key to continue . . .

是否可以仅检索注册表项的“数据”部分?

3 个答案:

答案 0 :(得分:30)

for /f "tokens=2*" %%a in ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\10.0" /v AppPath') do set "AppPath=%%~b"
echo %AppPath%
pause

答案 1 :(得分:0)

下面的命令确实起作用,例如我想获取 OS 名称:

for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| findstr "REG_"') do @echo %%b

输出为:

Windows 10 Enterprise

答案 2 :(得分:-2)

感谢您的回答,此处还可以添加一个字符串到值:

for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\...." /v keyname') do set "AppPath=%%~b"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\..." /v "keyname" /f /t REG_SZ /d "%AppPath% appended value"