Solved

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

Posted on 2012-03-23
8
1,415 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 52

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
 
LVL 52

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
DevOps Toolchain Recommendations

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

 
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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now