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

前端 未结 17 2605
抹茶落季
抹茶落季 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:17

    You can get the value of a registry key as follows

    @echo OFF
    setlocal ENABLEEXTENSIONS
    set REG_NAME="HKEY_CURRENT_USER\Software\Test"
    set KEY_NAME=TestVal
    
    FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %REG_NAME% /v %KEY_NAME% 2^>nul`) DO (
        @echo %%A : %%C
    )
    pause
    

    those who wonder how to add reg keys, here is a way.

    REGEDIT4
    
    ; @ECHO OFF
    ; CLS
    ; REGEDIT.EXE /S "%~f0"
    ; EXIT
    
    [HKEY_CURRENT_USER\Software\Test]
    "TestVal"="Succeeded"
    

提交回复
热议问题