Question

  Asked: Mar 7 2008   4:53 AM GMT
  Asked by: ELtangaZ


.Bat that extracts an specific regsitry key (SID) to a .txt or .reg file


Batch files, SID, Registry

Hello, how can i extract only the exact SID key from the registry with a .bat like this:

ExtractSID.bat:
REG QUERY HKU |Findstr /R "DEFAULT S-1-5-[0-9]*-[0-9-]*$" >> SID.txt

With result on file SID.txt:
HKEY_USERS\.DEFAULT
HKEY_USERS\S-1-5-21-57989841-484763869-1957994488-1003

What i need on SID.txt:
S-1-5-21-57989841-484763869-1957994488-1003

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



You may want to look into using the FOR command to process the SID.txt file line by line looking for the line which doesn't end in .DEFAULT.

Something like (this isn't tested):
FOR /F "delims=\ skip=1 tokens1,2" %%a in (SID.txt) do echo %%b > SID.txt
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Microsoft Windows and Security.

Looking for relevant Microsoft Windows Whitepapers? Visit the SearchWinIT.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

TomWahl  |   Mar 7 2008  4:06PM GMT

Add a line that filters using the FIND command to exclude lines with a specific string in them.

type SID.txt | find /v /i “default” >ONLY_SID.txt

The /v tells FIND to ignore the string “default” and the /i makes it case insensitive.

 

TQuinnelly  |   Mar 7 2008  11:32PM GMT

Just to add to Mrdenny’s answer…check out this site for some great command line reference.