View Full Version : Registry query to text file (WXP-Pro)
scull
06-13-2006, 12:30 PM
I had a quick question and I was unable to find an answer else where. I need to write a script that queries all the PC's on my network for certain or all programs and returns the data to a text file. Any help on how to get started?
Much Appreicated
motoflop
06-15-2006, 02:56 AM
If you are happy with windows batch scripts and know names of computers on your domain, try something like this:
@echo off
setlocal
rem set list of computers to scan
set pclist=alpha beta gamma delta
rem Initialize result file (this deletes possible old result file)
echo Software on computers %pclist% >result.txt
call :doit %pclist%
endlocal
goto :EOF
rem routine to scan one computer
:doit
rem Test if parameters are processed
if "%1"=="" goto :EOF
set pc=%1
echo Scanning %pc% start
echo ==== Software for %pc% >>result.txt
reg query \\%pc%\hklm\software >>result.txt
echo Scanning %pc% end
rem Switch next argument to %1
shift
rem Go back to start of this subroutine
goto :doit
That scipt queries registry for listed computers and writes one reulst file. If you are interested on only certain software, check which registry key you should list to see if that software is installed. This model script lists all subkeys under HKLM\software.
So first step is to get list of computers and then determine which registry key should be checked.
You can use same technique to check specific files or directories on target computers. Just remember that normally windows computer has hidden share C$ which refers to whole C- drive. So to check for folder c:\temp, use test like this:
if exist \\%pc%\c$\temp echo Computer %pc% has folder c:\temp >>result.txt
scull
06-15-2006, 08:55 AM
Thanks for your reply. I have some experience in using batch scripts however I am still learning.
rem set list of computers to scan
Is this where I list the name of the computers?
Thanks for your help! :)
motoflop
06-16-2006, 08:42 AM
Yes, that's where you list the computer names. That example contains those sample names "alpha beta gamma delta". You just put there real names whatever they are. You can also change the script to read computer names from some file if thats more feasible for you. Use command like:
for /f "tokens=1 delims=, " %i in (computernamelist.txt) do call :doit %i
That command reads computernamelist.txt line by line and extracts first blank or comma separated word and stores it to %i.
You can get help of batch commands using commands like these:
FOR /?
SET /?
CMD /?
IF /?
GOTO /?
For example SET command has ability to extract substrings, which might be handy. Many people writing scripts don't know these. Perhaps they haven't thougt that script commands could have such easy help available.
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.