Solved

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

Posted on 2012-03-23
8
1,446 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
[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
  • 4
  • 3
8 Comments
 
LVL 54

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 54

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 54

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

735 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