Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-23
8
Medium Priority
?
1,509 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 59

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 1200 total points
ID: 37759781
Try this for each application

wmic /failfast:on product where "name like 'openoffice%'" call uninstall /nointeractive
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 59

Assisted Solution

by:Bill Prew
Bill Prew earned 800 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 59

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Loops Section Overview
Suggested Courses

926 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