How can I get the value of a registry key from within a batch script?

前端 未结 17 2579
抹茶落季
抹茶落季 2020-11-27 15:12

I need to use a REG QUERY command to view the value of a key and set the result into a variable with this command:

FOR /F \"tokens=2* delims=    \" %%A IN (\         


        
17条回答
  •  Happy的楠姐
    2020-11-27 15:28

    @echo off
    setlocal ENABLEEXTENSIONS
    set KEY_NAME=HKLM\SOFTWARE\Wow6432Node\Acme Software Inc\Common
    set VALUE_NAME=InstallDir
    
    FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set pInstallDir=%%B)
    echo %pInstallDir%
    

    That works for me in Win7 where the key has a space and the value also has a space. So saving the above in c:\temp as test.bat, open a cmd window and run it.

    C:\temp>test

    C:\Program Files (x86)\acme Software Inc\APP\

提交回复
热议问题