Solved

Batch File[Advanced]: FOR Sub-loop does not work

Posted on 2012-03-24
4
691 Views
Last Modified: 2012-03-24
Hi there,

The FOR loop between lines 13 and 17 does not work.  However, if I remove it from the FOR...%%A... loop, it works.

Could you please fix it?
And while at it, if you have ideas to improve my script, please share your wisdom.

Thanks for your help,
Rene

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET LogFile=%~dpn0.log

ECHO %date% %time% START>>"%LogFile%"
ECHO ----------------------------------->>"%LogFile%"

FOR /F "delims=\ " %%A IN ('NET VIEW ^| FINDSTR -i "\\') DO (
   SET Flag=0
   ECHO [%%A]

   REM LISTING PROGRAMS TO BE UNINSTALLED
   FOR /F "tokens=2 delims=," %%B in ('wmic /node:"%%A" product get caption^,name /format:csv ^| findstr -i "LibreOffice OpenOffice"') DO (
      SET Flag=1
      ECHO %Date% %Time% [%%A] Will be uninstalled [%%B]
      ECHO %Date% %Time% [%%A] Will be uninstalled [%%B]>>"%LogFile%"
   )

   REM UNINSTALLING UNWANTED APPS
      IF !Flag! == 1 (
         WMIC /node:"%%A" /failfast:on product where "name like 'LibreOffice%%' or name like 'OpenOffice%%'" call uninstall /nointeractive
         ECHO %Date% %Time% [%%A] Programs uninstalled [!errorlevel!]>>"%LogFile%"
      )

   REM IF MICROSOFT OFFICE IS NOT INSTALLED, INSTALL LIBRE OFFICE
      WMIC /node:"%%A" product get name | findstr -i /C:"MICROSOFT OFFICE" >NUL
      IF !errorlevel! == 0 (
         ECHO "\\%%A" [MICROSOFT OFFICE IS INSTALLED]
         ECHO %Date% %Time% [%%A] Microsoft Office is installed>>"%LogFile%"
      ) ELSE (
         ECHO \\%%A [INSTALLING LIBRE OFFICE]
         SET Folder=\\%%A\C$\Temp
         IF NOT EXIST "!Folder!" MD "!Folder!"
         
         XCOPY /Y /I "LibO_3.5.1_Win_x86_install_multi.msi" "!Folder!"
         PSEXEC \\%%A C:\Windows\System32\msiexec.exe /i "C:\Temp\LibO_3.5.1_Win_x86_install_multi.msi" -qb
         
         ECHO %Date% %Time% [%%A] LibreOffice_3.5.1 has been installed [!errorlevel!]>>"%LogFile%"
         DEL /f /q "!Folder!\LibO_3.5.1_Win_x86_install_multi.msi"
      )
   ECHO --------------------------------------------
   ECHO. >>"%LogFile%"
)

ECHO ----------------------------------->>"%LogFile%"
ECHO %date% %time% COMPLETED>>"%LogFile%"
ECHO.>>"%LogFile%"

PAUSE
EXIT

Open in new window

0
Comment
Question by:ReneGe
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
paultomasi earned 500 total points
ID: 37761212
Line 8 should be:

    FOR /F "delims=\ " %%A IN ('NET VIEW ^| FINDSTR -i "\\"') DO (

(you missed the closing double-quote after '\\')

Does it still require attention?
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37761235
Thats a good one ;)

I guess I should rest this weekend...

Thanks Paul

Cheers,
Rene
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37761238
You can also delete lines 17 through 20 - although, I guess this is intentional while you're testing the inner FOR-loop between lines 13 and 17.
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37761245
No probs ReneGe, it happens to the best of us... and I've pulled my hair out and screamed on many occasions!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now