Jump to content

Query Registry, Output to txt file


chilifrei64

Recommended Posts

I gotta problem guys(and gals).. I gotta new client and they have this crappy software. The software is licensed in such a way that only computers with a specific Workstation ID are able to access it. This information is stored in the registry on all the workstations. It only allows one workstation ID to be logged in at the same time. Well we built up a new computer today for them and I found out about all this and spent about a half an hour trying to find an open Workstation ID.

Since I am now managing the network.. I want to have this documented so I dont spend a half an hour trying many different numbers. I was able to construct a reg query to find the value of the key on the remote machines.

What I am looking for is a way to output the results to a txt file. The reg query goes as follows

reg query "\\lf-accnt01\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"

How can I write a batch file to read the computer names from a list and output these results so I can have them handy?

Thanks in advance...

Link to comment
Share on other sites


Try the following:

reg query "\\lf-accnt01\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID" > c:\id_log.txt

Or this to echo it to a network fileshare instead:

reg query "\\lf-accnt01\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID" > \\servername\sharename\id_log.txt

Of course, you'll need to configure the permissions appropriately on the share.

Additionally, using >> as opposed to > allows you to append to the end of a file rather than overwriting it.

- Ravashaak

Edited by ravashaak
Link to comment
Share on other sites

Hmmm, maybe I misunderstood you. I'm not sure now that I'm 100% clear on exactly what you mean by the following:

How can I write a batch file to read the computer names from a list and output these results so I can have them handy?

- Ravashaak

Edited by ravashaak
Link to comment
Share on other sites

Basically.. you see the begining of the query I have the computer name \\lf-accnt01

I have over 100 computers to run this on... as opposed to manually adding the computer name.. how can i have it read a list or is this not possible with batch programming?

Thanks for the quick response though..

I am gonna try it as a computer logon script and see if it will append the the file

Edited by chilifrei64
Link to comment
Share on other sites

Try something like this

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET _MACLIST="\\servername\sharename\\_PCNAMES.TXT"
SET _RESULTS="\\servername\sharename\\_OUTPUT.TXT"
IF NOT EXIST %_MACLIST% (
TYPE NUL>%_MACLIST%
FOR /F %%a in ('NET VIEW ^|FIND "\\"') DO ECHO/%%a>>%_MACLIST%
)
IF EXIST %_RESULTS% DEL /Q %_RESULTS%
FOR /F %%b IN (%_MACLIST%) DO CALL :NEXT "%%b"
ENDLOCAL
GOTO :EOF
:NEXT
SET _NAME=%~1
FOR /F "TOKENS=3 DELIMS= " %%c ('REG QUERY "\\%_NAME%\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"') DO ECHO/%_NAME%=%%c>>%_RESULTS%
GOTO :EOF

Just change the locations for _MACLIST and _RESULTS to suit.

<Edit>

Note - DELIMS=<tab>"

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Oh wow.. thanks alot.. this looks like it is going to do it..however it is not completing the task

I get

C:\>wsid.bat

('REG was unexpected at this time.

I named it wsid.bat.

I double checked the formatting but was unable to find any errors. My notepad looks identical to this. May I be missing something?

Thanks again for the help.. you may have saved me a lot of time..

Link to comment
Share on other sites

missed out 'IN' on next to last line

  • FOR /F "TOKENS=3 DELIMS= " %%c IN ('REG

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET _MACLIST="\\servername\sharename\_PCNAMES.TXT"
SET _RESULTS="\\servername\sharename\_OUTPUT.TXT"
IF NOT EXIST %_MACLIST% (
TYPE NUL>%_MACLIST%
FOR /F %%a in ('NET VIEW ^|FIND "\\"') DO ECHO/%%a>>%_MACLIST%
)
IF EXIST %_RESULTS% DEL /Q %_RESULTS%
FOR /F %%b IN (%_MACLIST%) DO CALL :NEXT "%%b"
ENDLOCAL
GOTO :EOF
:NEXT
SET _NAME=%~1
FOR /F "TOKENS=3 DELIMS= " %%c IN ('REG QUERY "\\%_NAME%\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"') DO ECHO/%_NAME%=%%c>>%_RESULTS%
GOTO :EOF

<Edit>

Another error fixed, however please see shorter version in my next reply

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Thank you so much for your help.. I do appreciate it..

The script is running now however it is not reading the txt file. When I leave echo on this is what I receive

C:\>FOR /F "TOKENS=3 DELIMS= " %c IN ('REG QUERY "\\\\srv-dcex02\Tech\\_PCNAMES.TXT\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"') DO ECHO/\\srv-dcex02\Tech\\_PCNAMES.TXT=%c 1>>"\\srv-dcex02\Tech\\_OUTPUT.TXT"

It is putting the path to the txt file as opposed to reading the txt file.

And can I just say that I think it is amazing how powerful DOS still is.. I started off in the windows 2000 era and didnt play with much of dos.. I knew you could write batch programs to automate tasks but I had no idea you could parse a file for computer names and output results to a file using it.. I would have instantly thought VB or Javascript..

Once again thanks for all your help

Link to comment
Share on other sites

Sorry for not responding sooner or I would have helped you with the FOR loop and parsing stuff. Glad someone else got to it and helped. I tend to get busy lately trying to take care of a million things due to hurricane katrina's mess.

And I too am amazed at the sheer utility of DOS/Windows Command environment. And if you add a few free utilities here and there, it becomes even more powerful.

- Ravashaak

Edited by ravashaak
Link to comment
Share on other sites

Try this slightly tidier version, you only have to verify that %_MYLOCN% is correct

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET _MYLOCN=\\srv-dcex02\Tech\
PUSHD %_MYLOCN%
IF NOT EXIST _PCNAMES.TXT (
FOR /F %%a in ('NET VIEW ^|FIND "\\"') DO ECHO/%%a>>_PCNAMES.TXT
)
IF EXIST _OUTPUT.TXT DEL /Q _OUTPUT.TXT
FOR /F "TOKENS=*" %%b IN (_PCNAMES.TXT) DO CALL :NEXT "%%b"
POPD
ENDLOCAL
GOTO :EOF
:NEXT
SET _NAME=%~1
FOR /F "TOKENS=3 DELIMS= " %%c IN ('REG QUERY "%_NAME%\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID" ^2^>nul') DO IF ERRORLEVEL 0 (ECHO/%_NAME%=%%c>>_OUTPUT.TXT)
GOTO :EOF

Hopefully will just be a case of checking the results to verify that the correct tokens were used for the specific registry key you are looking at.

<Edit>

Slight changes made according to message below.

If the _output.txt isn't being created now, there is an error with the query

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

We are getting closer

I have been letting the script write the _PCNAMES.TXT. When it creates it it puts the \\ in the txt file.. Then when the script calls it it was adding a second \\ therefore making it look like \\\\ComputerName.. which wasnt working.. I removed the \\ at ('REG QUERY "\\%_NAME%\.... to look like ('REG QUERY "%_NAME%\.....

and now it runs completely and seems to find it.. however it is not writing an _OUTPUT.TXT file anywhere.. I checked the local machine and the server it is writing to.. The _PCNAMES.TXT gets created in the server share but output does not..

any ideas?

Link to comment
Share on other sites

Thanks hyper hacker but I already have a list of the workstations, weather it be in my documentation, active directory exports or any of the other ways to get a computer list.. I am trying to get the batch file that Yzöwl has constructed to output the results of a query ran off the list that I already have. Thank you though

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...