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

前端 未结 17 2557
抹茶落季
抹茶落季 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条回答
  •  孤城傲影
    2020-11-27 15:15

    This works if the value contains a space:

    FOR /F "skip=2 tokens=1,2*" %%A IN ('REG QUERY "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul') DO (
        set ValueName=%%A
        set ValueType=%%B
        set ValueValue=%%C
    )
    
    if defined ValueName (
        echo Value Name = %ValueName%
        echo Value Type = %ValueType%
        echo Value Value = %ValueValue%
    ) else (
        @echo "%KEY_NAME%"\"%VALUE_NAME%" not found.
    )
    

提交回复
热议问题