Extracting specific registry key from REG QUERY based on search string

3.2k views Asked by At

I am trying to extract the key value of a registry entry. I only want the key which I have been trying to concatenate using FOR /F, however had no luck.

Eg: the command

REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f chrome

returns

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{157F97DF-A001-36FB-A90C-55949FA130CA}
DisplayName    REG_SZ    Google Chrome
End of search: 1 match(es) found.

All that I want from this result is 157F97DF-A001-36FB-A90C-55949FA130CA

How can I do this using FOR /F or other similar methods?

Many thanks!!

1

There are 1 answers

0
MC ND On BEST ANSWER

You can try to split the lines using {} as delimiters

@echo off
    setlocal enableextensions disabledelayedexpansion

    for /f "tokens=2 delims={}" %%a in ('
        REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f chrome
    ') do set "value=%%a"

    echo %value%