Output problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Lord_Ice
Posts: 3
Joined: 06 Aug 2010 04:02

Output problem

#1 Post by Lord_Ice » 06 Aug 2010 04:27

Hi all,
I have a big problem with a batch file :D .
I copied this script in all the workstation of my network. I use to execute it remotely from my PC every week:
This is the code:

Code: Select all

@echo off

set DC=\\COMPUTER
set data=%date%
set ora=%time%
set dati=%DC%\SOFTINST$\LOG\%COMPUTERNAME%.txt
set prgs=%DC%\SOFTINST$\%COMPUTERNAME%.txt
set fooreg=%temp%\foo.reg
set footmp=%temp%\foo.tmp
set foolog=%temp%\foo.log
set foolist=%temp%\foo.list

:LOG
REM Creazione log macchina e interrogazione sistema
if exist %fooreg% del %fooreg%
if exist %footmp% del %footmp%
if exist %foolog% del %foolog%
if exist %foolist% del %foolist%
echo Nome Computer:                      %COMPUTERNAME%>> %foolog%
echo Data ultimo aggiornamento:          %data%>> %foolog%
echo Ora ultimo aggiornamento:           %ora% >> %foolog%
IF EXIST %dati% GOTO DELETEOLDLOG
type %foolog% >> %dati%
del %foolog%
GOTO LISTA

:DELETEOLDLOG
erase %dati%
type %foolog% >> %dati%
del %foolog%

:LISTA
REM Interrogazione sul software installato.
echo "%COMPUTERNAME%.txt" >> %footmp%
regedit /E %fooreg% HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
type %fooreg% | find """DisplayName""" >> %foolist%
for /f "tokens=2,3 delims==" %%a in (%foolist%) do (echo %%a >> %footmp%)
del %fooreg%
IF EXIST %prgs% GOTO DELETEOLDLIST
type %footmp% >> %prgs%
del %footmp%
GOTO EXIT

:DELETEOLDLIST
erase %prgs%
type %footmp% >> %prgs%
del %footmp%

:EXIT
echo.
echo TRUE >> C:\TRUE.CK
GOTO :eof

In :LISTA, the batch audit the windows registry for all installed software and save it in a txt file.

For Example:
"WORKSTATION.txt"
"Windows Driver Package - Intel (Serial) Ports (07/06/2009 5.5.1.1012)"
"Windows Driver Package - Intel System (05/27/2008 9.0.0.1009)"
"CCleaner"
"Cronos ZERO12 Monopostazione 3.1.1"
"DameWare Development Mirror Driver Uninstall"
"Defraggler"
"DWG TrueView 2011"
"Windows Driver Package - Intel System (09/15/2006 7.0.0.1011)"
"Windows Driver Package - Intel USB (02/25/2008 9.0.0.1005)"
"Windows Driver Package - Intel System (02/25/2008 9.0.0.1005)"
"GoldenDict"
...
...

I'm trying to write it all in one row without success. I need only one file with one computer for each row and not like now, one file for every computer.

For example:
"WORKSTATION1.txt";"SOFT1";"SOFT2";"SOFT3";"SOFT4";...;...
"WORKSTATION2.txt";"SOFT1";"SOFT2";"SOFT3";"SOFT4";...;...


Any Idea??

I hope to solve this problem :(

Thanks guys.....

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Output problem

#2 Post by avery_larry » 06 Aug 2010 10:58

If it's not too long then basically instead of echo'ing the stuff into the file one line at a time -- use a set command to append the stuff onto a variable and then echo that variable into the file.

I *think* it would be these lines:

Code: Select all

for /f "tokens=2,3 delims==" %%a in (%foolist%) do set footmpvar=%%a;!footmpvar!

...

echo.%footmpvar%>>%prgs%


You'll need:

setlocal enabledelayedexpansion

for it to work.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Output problem

#3 Post by !k » 06 Aug 2010 12:16


Lord_Ice
Posts: 3
Joined: 06 Aug 2010 04:02

Re: Output problem

#4 Post by Lord_Ice » 07 Aug 2010 09:46

Thanks to everyone..

avery_larry: use the variable instead of echo was a good idea. Now is working as i wanted.

!k: i'll read that post....

thanks guys for your time... :mrgreen:

Lord_Ice
Posts: 3
Joined: 06 Aug 2010 04:02

Re: Output problem

#5 Post by Lord_Ice » 11 Aug 2010 08:32

@avery_larry:

This was a good idea but is not working properly under windows 2000. The software list is incomplete. Is like if the variable is not enough big for store all the entries.

Here the code:

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

set DC=\\FERW0202
set dati=%DC%\SOFTINST$\LOG\%COMPUTERNAME%.txt
set prgs=%DC%\SOFTINST$\Inventario.txt
set fooreg=%temp%\foo.reg
set footmp=%temp%\foo.tmp
set foolog=%temp%\foo.log
set foolist=%temp%\foo.list
if exist TRUE.CK del TRUE.CK

:LOG
REM Creazione log macchina e interrogazione sistema
if exist %fooreg% del %fooreg%
if exist %footmp% del %footmp%
if exist %foolog% del %foolog%
if exist %foolist% del %foolist%
echo Nome Computer:                      %COMPUTERNAME%>> %foolog%
echo Data ultimo aggiornamento:          %date%>> %foolog%
echo Ora ultimo aggiornamento:           %time% >> %foolog%
type %foolog% > %dati%

:LISTA
REM Interrogazione sul software installato.
regedit /E %fooreg% HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
type %fooreg% | find """DisplayName""" >> %foolist%
REM for /f "tokens=2,3 delims==" %%a in (%foolist%) do (echo %%a >> %footmp%)
for /f "tokens=2,3 delims==" %%a in (%foolist%) do set footmpvar=%%a;!footmpvar!
del %fooreg%
set footmpvar=%COMPUTERNAME%;!footmpvar!
echo.%footmpvar% >> %prgs%

:EXIT
echo.
echo TRUE > C:\TRUE.CK
unset footmpvar
GOTO :eof


Is working good under XP and Vista but not with 2000 :-(.

@!k:
Your solution is working good...

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

REM Creazione _CHO.COM
@echo off
chdir /d "%~dp0"
set "scr=%~dp0\_cho.scr"
echo N _CHO.COM> "%scr%"
echo E 0100 BB 80 00 43 80 3F 0D 75 FA C6 07 24 B4 09 BA 82>> "%scr%"
echo E 0110 00 39 DA 7F 02 CD 21 B4 4C CD 21>> "%scr%"
for %%s in (RCX 001B W Q) do echo %%s>> "%scr%"
debug< "%scr%" >nul
del "%scr%" /q

set DC=\\FERW0202
set dati=%DC%\SOFTINST$\LOG\%COMPUTERNAME%.txt
set prgs=%DC%\SOFTINST$\Inventario.txt
set fooreg=%temp%\foo.reg
set footmp=%temp%\foo.tmp
set foolog=%temp%\foo.log
set foolist=%temp%\foo.list
if exist TRUE.CK del TRUE.CK

:LOG
REM Creazione log macchina e interrogazione sistema
if exist %fooreg% del %fooreg%
if exist %footmp% del %footmp%
if exist %foolog% del %foolog%
if exist %foolist% del %foolist%
echo Nome Computer:                      %COMPUTERNAME%>> %foolog%
echo Data ultimo aggiornamento:          %date%>> %foolog%
echo Ora ultimo aggiornamento:           %time% >> %foolog%
type %foolog% > %dati%

:LISTA
REM Interrogazione sul software installato.
_cho.com "%COMPUTERNAME%"; >> %footmp%
regedit /E %fooreg% HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
type %fooreg% | find """DisplayName""" >> %foolist%
for /f "tokens=2,3 delims==" %%a in (%foolist%) do (_cho.com %%a; >> %footmp%)
del %fooreg%
echo.>>%footmp%
type %footmp% >> %prgs%
del %footmp%

:EXIT
echo.
echo TRUE > C:\TRUE.CK
GOTO :eof


And at the end I get the list formatted as i want....

Thanks to all....

Post Reply