Solved

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

Posted on 2012-03-24
4
696 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell logging 1 33
IntelliJ and Eclipse Neon 2 installations 4 65
Move files based on file names? 8 67
Cannot locate cell 15 40
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

737 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