chilifrei64 Posted September 30, 2005 Posted September 30, 2005 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 followsreg 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...
ravashaak Posted September 30, 2005 Posted September 30, 2005 (edited) Try the following:reg query "\\lf-accnt01\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID" > c:\id_log.txtOr 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.txtOf 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 September 30, 2005 by ravashaak
ravashaak Posted September 30, 2005 Posted September 30, 2005 (edited) 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 September 30, 2005 by ravashaak
chilifrei64 Posted September 30, 2005 Author Posted September 30, 2005 (edited) Basically.. you see the begining of the query I have the computer name \\lf-accnt01I 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 September 30, 2005 by chilifrei64
Takeshi Posted September 30, 2005 Posted September 30, 2005 (edited) Perhaps you can use for /f "usebackq" in do to parse the contents of a filename and run reg query. Edited September 30, 2005 by Takeshi
Yzöwl Posted September 30, 2005 Posted September 30, 2005 (edited) Try something like this@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET _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"ENDLOCALGOTO :EOF:NEXTSET _NAME=%~1FOR /F "TOKENS=3 DELIMS= " %%c ('REG QUERY "\\%_NAME%\HKLM\SOFTWARE\InterNetworX Systems\ICS\Configuration" /v "Workstation ID"') DO ECHO/%_NAME%=%%c>>%_RESULTS%GOTO :EOFJust change the locations for _MACLIST and _RESULTS to suit.<Edit>Note - DELIMS=<tab>"</Edit> Edited September 30, 2005 by Yzöwl
chilifrei64 Posted September 30, 2005 Author Posted September 30, 2005 Oh wow.. thanks alot.. this looks like it is going to do it..however it is not completing the taskI getC:\>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..
Yzöwl Posted September 30, 2005 Posted September 30, 2005 (edited) missed out 'IN' on next to last lineFOR /F "TOKENS=3 DELIMS= " %%c IN ('REG@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET _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"ENDLOCALGOTO :EOF:NEXTSET _NAME=%~1FOR /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 October 1, 2005 by Yzöwl
chilifrei64 Posted October 1, 2005 Author Posted October 1, 2005 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 receiveC:\>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
ravashaak Posted October 1, 2005 Posted October 1, 2005 (edited) 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 October 1, 2005 by ravashaak
Yzöwl Posted October 1, 2005 Posted October 1, 2005 (edited) Try this slightly tidier version, you only have to verify that %_MYLOCN% is correct@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET _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.TXTFOR /F "TOKENS=*" %%b IN (_PCNAMES.TXT) DO CALL :NEXT "%%b"POPDENDLOCALGOTO :EOF:NEXTSET _NAME=%~1FOR /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 :EOFHopefully 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 October 1, 2005 by Yzöwl
chilifrei64 Posted October 1, 2005 Author Posted October 1, 2005 We are getting closerI 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?
HyperHacker Posted October 1, 2005 Posted October 1, 2005 If you just want to get a list of computer names, you could use this to copy it from the Network Neighbourhood file listing.
chilifrei64 Posted October 1, 2005 Author Posted October 1, 2005 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
nmX.Memnoch Posted October 2, 2005 Posted October 2, 2005 These machines are in a domain...correct? Are you running any sort of logon scripts?
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now