Avatar of urfried
urfried
Flag for Netherlands asked on

cmd echo all, except lines that contains. (whitelist software that is ok, but output non-whitelisted)

Ola gents,

We created some batch to find all installed programs on workstations.
we would like to filter out a whitelist, and echo the non-whitelisted.

For instance....Filter out all software that contains:
"Security"
"Microsoft"
"ESET"
enz. enz.

And echo the software that isn't whitelisted.

All help is appreciated.
Thanx in advance.


setlocal enabledelayedexpansion

for /f "tokens=*" %%i in ('reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /s ^|findstr /R "\<DisplayName"') do (
                                   set /a cl+=1
                                   set softw_!cl!=%%i
                                   )
for /l %%i in (1, 1, %cl%) do      (
			        set softw_%%i=!softw_%%i:~19!
			        echo !softw_%%i!
			        )

Open in new window

software.txt
Microsoft DOS

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
Randy Downs

Maybe something like this & just nest the if loops to find all your files you want to exempt. Have the else print the rest.

http://www.computerhope.com/if.htm

IF string1==string2 (
#Next If check) ELSE (
echo string)

ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
urfried

ASKER
As always... it works as requested.
Better then expected too !

Thanx ..(again)
It looks so easy... :)

Grtz
Bill Prew

Just to offer a slightly different (and maybe faster?) approach (I couldn't resist), how about this approach?

Basic idea is get the list of installed software products into a text file ALL.TXT, then use FINDSTR to display only the lines that are not in the software.txt file.

@echo off
(for /F "tokens=2*" %%A in ('reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /s ^|findstr /R "\<DisplayName"') do echo %%B)>all.txt
findstr /i /b /v /g:software.txt all.txt>some.txt
del all.txt

Open in new window

~bp
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23