Need batch to append text with machine name

July 25, 2011 at 10:30:52
Specs: Windows XP
Hi All,

I'm completely new to batch scripting and have spent a few hours researching a problem with not much success so far.

I have about 150 Windows XP PCs across a Windows domain, and all have a program installed on them that required a recent addition to an .ini file found in, for the sake of this conversation, "C:\Documents and Settings\All Users\Application Data\BlahBlahProgram\BlahBlah.ini" The fix involved adding a simple line of text, for example, "BlahFix=1", to every PCs .ini file in that location. This fix was pushed out using a proprietary, commercial inventory management solution.

I'd like to construct a batch script to go back and double check that the fix was successfully pushed to each device. I would anticipate the batch can be run on each PC to look in "C:\Documents and Settings\All Users\Application Data\BlahBlahProgram\BlahBlah.ini" and, if the line "BlahFix=1" is present in the .ini, export that PCs name to a 'success' log file on my NAS, for example "\\nas\BlahBlah\FixQuery\FixSuccessful.txt".

If it's simple enough to run a similar process to export a machine name to a second, separate log file kept for PCs that do not have the entry in the .ini file, that would be great too. If not, I'm fine to just compare the contents of the 'successful' log against the list of PCs I know the fix was pushed to.

So far I have:

@Echo off
find /i "BlahFix=1" "C:\Documents and Settings\All Users\Application Data\BlahBlahProgram\BlahBlah.ini"
if errorlevel 0 echo %COMPUTERNAME% >> "\\nas\BlahBlah\FixQuery\FixQuery.txt"

The problem is that when tested on PCs where the .ini does not have "BlahFix=1" the batch still appends the text file on the NAS with its machine name, as though the entry were in the .ini. I'm sure this is something extremely simple I'm overlooking. Thoughts?

Thanks in advance.

See More: Need batch to append text with machine name

Report •

July 25, 2011 at 10:47:14
Actually, it seems I may have solved it by adding a similar errorlevel 1 entry before the
errorlevel 0 one:

if errorlevel 1 echo %COMPUTERNAME% >> "\\nas\BlahBlah\FixQuery\unsuccessful.txt"

if errorlevel 0 echo %COMPUTERNAME% >> "\\nas\BlahBlah\FixQuery\successful.txt"

If anyone sees a better way I'm still all ears.


Report •
Related Solutions

Ask Question