Page 1 of 1

Need some minor help perfecting this batch registry query

Posted: 30 Sep 2011 12:29
by BrentNewland
Output of REG QUERY "HKLM\Software\1234567890\123\WinPE\BoundOperatingSystem\HKEY_USERS" /f S-1-5*-1000 /d

Code: Select all

HKEY_LOCAL_MACHINE\Software\1234567890\123\WinPE\BoundOperatingSystem\HKEY_USERS
    S-1-5-21-974480208-2472847273-1695335269-1000    REG_SZ    S-1-5-21-974480208-2472847273-1695335269-1000
    S-1-5-21-974480208-2472847273-1695335269-1000_Classes    REG_SZ    S-1-5-21-974480208-2472847273-1695335269-1000_Classes

End of search: 2 match(es) found.


Batch file code:

Code: Select all

For /F "Skip=2 Tokens=3" %%A in ('REG QUERY "HKLM\Software\1234567890\123\WinPE\BoundOperatingSystem\HKEY_USERS" /f S-1-5*-1000 /d') Do (
Set pn=%%A)


Result of the batch file:

Code: Select all

G:\>(Set pn=S-1-5-21-974480208-2472847273-1695335269-1000 )

G:\>(Set pn=S-1-5-21-974480208-2472847273-1695335269-1000_Classes )

G:\>(Set pn=search: )


What I need is the value without the "_classes". As you can see, it sets it right the first time, but then changes the value two more times. Any way to just have it do the one?

Re: Need some minor help perfecting this batch registry quer

Posted: 30 Sep 2011 23:29
by dbenham
You can pipe the REG QUERY output to FINDSTR and use a regular expression to filter the results:

Code: Select all

for /f "tokens=3" %%A in ('REG QUERY "HKLM\Software\1234567890\123\WinPE\BoundOperatingSystem\HKEY_USERS" /f S-1-5*-1000 /d^|findstr /r /c:" S-1-5[^ ]*-1000 "') do set pn=%%A


FINDSTR is primitive with its regular expression support, but you can still get quite specific.

Dave Benham