Search code examples
windowsbatch-fileregistry

Looping thru win 7 registry to find a key's value


In a previuos question, I needed to edit a value in a key in the win 7 registry ( REG ADD - Invalid syntax ). Now I need to loop thru the Profiles to find a specific key where value of a subkey is the string "Network".

The registry looks like this: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\ with these subkeys:

{1C2A5700-E8E8-41C0-9684-6FB69FA73888}

ProfileName REG_SZ SomethingElse

{7AA5E1AE-2408-4B92-9C56-8962CD9E926C}

ProfileName REG_SZ Network

Here is my reg command

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /s /v ProfileName

I want to find the keyname where the subkey "ProfileName" equals "Network". I know I will have to use a FOR loop but I have know idea how to do this.

my final result should return keyname {7AA5E1AE-2408-4B92-9C56-8962CD9E926C}

Any help will be greatly appreciated.


Solution

  • Something like this may help:

    @echo off    
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /d /f "Network" /s /e
    pause
    

    I haven't tested it but by following the details in this, I surmise that it should perform what's required.

    EDIT

    Extracting the subkey name alone...

    @echo off
    
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /d /f "Network" /s /e > result.txt
    for /f "tokens=1*delims=:" %%i in ('findstr /n "^" result.txt') do if %%i equ 2 echo %%~nj
    del /q result.txt
    pause