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
Solved

Batch File [ADVANCED]: Uninstall remote apps [WMIC in a FOR loop]

Posted on 2012-03-23
8
1,434 Views
Last Modified: 2012-03-24
Hi there,

In line 11, the data is extracted in a way that lines 14 and 15 does not work as expected.

Thanks for your help,
Rene

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

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

FOR /F "delims=\ " %%A IN ('NET VIEW ^| FINDSTR -i "\\"') DO (
   ECHO [%%A]
   REM UNINSTALLING "PROGRAMS"
      FOR /F "delims=" %%B in ('wmic /node:"%%A" product get name ^| findstr -i "LibreOffice OpenOffice"') DO (
         SET ProductName=%%B
         SET ProductName=!ProductName: =_!
         ECHO UNINSTALLING [%%B]
         WMIC /failfast:on /node:"%%A" product where name="%%B" call uninstall /nointeractive
         SET Result=%%A=!ProductName!=UNINSTALLED:!errorlevel!
      )
)

REM CREATING LOG FILE
FOR /F "tokens=2-4 delims==" %%A in ('SET Result=') DO (
   ECHO [%%A] [%%B] [%%C] [%%D]
   ECHO %Date% %Time% [%%A] [%%B] [%%C]>>"%LogFile%"
)
ECHO ----------------------------------->>"%LogFile%"
ECHO %date% %time% COMPLETED>>"%LogFile%"
ECHO.>>"%LogFile%"
PAUSE
EXIT

Open in new window

0
Comment
Question by:ReneGe
  • 4
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37759644
Rene, what product are you looking for, it seems like you are getting the name attribute, for a product named "LibreOffice OpenOffice", so if you know the name why look for it?  Is it to see if it is installed?  Or is that only a partial substring of the full name?

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37759677
It is indeed a partial substring of the full name. The problem here is that Open Office and Libre Office includes the version number in the name. So I want to make sure all version are removed through out the network.

Thanks,
Rene
0
 
LVL 15

Accepted Solution

by:
achaldave earned 300 total points
ID: 37759781
Try this for each application

wmic /failfast:on product where "name like 'openoffice%'" call uninstall /nointeractive
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 53

Assisted Solution

by:Bill Prew
Bill Prew earned 200 total points
ID: 37759789
Yes, I was going to suggest using the LIKE operator in the WMIC command.  Take a look at this reference on WQL...

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394606%28v=vs.85%29.aspx

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37759811
Following achaldave command line and bill's reference URL on WQL, the following works:
wmic /node:"remotepcname" /failfast:on product where "name like 'openoffice%' or name like 'libreoffice%'" call uninstall /nointeractive

Open in new window


If a PC would have both programs, Open Office and Libre Office, would they both be uninstalled?

Thanks
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37759814
I think so, but I haven't used WMIC in that manner so don't take my word for it :-).

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37759906
Ok, here is the verdict!

I installed both apps, then ran the following:

wmic /node:"RemotePcName" /failfast:on product where "name like 'OpenOffice%' or name like 'LibreOffice%'" call uninstall /nointeractive

Both apps were uninstalled

Very cool!!

Thanks to you two :)

Cheers,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37761003
FYI

WMIC /node:"RemotePcName" /failfast:on product where "name like 'LibreOffice%' or name like 'OpenOffice%'"

Works when I run it in a command prompt.  When I run it from within a batch file, dos thinks that whatever is between the % is a variable name.

To resolve this, I replaced % by %%, as in:
WMIC /node:"RemotePcName" /failfast:on product where "name like 'LibreOffice%%' or name like 'OpenOffice%%'"

Cheers,
Rene
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
The viewer will learn how to dynamically set the form action using jQuery.
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…

856 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