Need some minor help perfecting this batch registry query

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Need some minor help perfecting this batch registry query

#1 Post by BrentNewland » 30 Sep 2011 12:29

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?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Need some minor help perfecting this batch registry quer

#2 Post by dbenham » 30 Sep 2011 23:29

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

Post Reply