Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-24
4
Medium Priority
?
700 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
paultomasi earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 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