So without getting to convoluted, the gist of what I am trying to accomplish is that I currently am listing the results from a reg query by display name of programs, assigning a number to it, and then calling it later by number. When it lists the results it then uses a findstr to filter specific programs (such as anything with microsoft in it) from the list because I don't want them to even be an option for uninstalling. Right now it works basically, except it returns like this:
Let's say the programs in the Registry are:
Microsoft Update (should be filtered)
Notepad
Java
Microsoft Word (should be filtered)
Yahoo Toolbar
When I run this:
: progList64
cls
set regVar=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
set opt=64
echo _______________________________________________________
echo.
echo Please wait while I compile a list of known programs...
echo _______________________________________________________
echo.
echo %tab%64bit Programs
echo Index%tab%Name
set count=0
for /f "tokens=2,*" %%a in ('Reg Query %regVar% /S^|find " DisplayName"') do (
set /a count+=1
setlocal EnableDelayedExpansion
for %%n in (!count!) do (
endlocal
set product[%%n]=%%b
echo %%n.%tab%%%b | findstr /V /C:"Microsoft" | findstr /V /C:"Dell" | findstr /V /C:"MDOP" | findstr /V /C:"MED"
)
)
echo _______________________________________________________
echo.
echo ============ PRESS 'M' TO GO TO MAIN MENU =============
echo.
goto uninstallerMenu
I get this:
2. Notepad
3. Java
5. Yahoo Toolbar
So later when I call from the array you can actually put in 1 or 4 and select that product even though it's not displayed. I'm trying to filter it before it prints that it only prints what I want, resulting in this:
1. Notepad
2. Java
3. Yahoo Toolbar
I've tryin using various IF statements, tried putting the entire for %%n in (!count!) part in an IF statement that tests if Microsoft, dell, etc are in the DisplayName and then only displaying and increasing the counter if it fits, but that's not working either. I'm at my wits end here, any ideas?
And unrelated and not really important, but does anyone know a better way of filtering rather than daiychaining an entire row of findstr statements? Like an exclude list or something?
At a quick guess, try, before the FOR
loop, (say after the SET COUNT...
)
set excluded=Microsoft Dell MDOP MED
Then cascade
|findstr /v "%excluded%"
after the FIND " Displayname"
This should filter out any of the space-separated words in excludeme
Your existing cascaded findstr
can then be removed as those names are removed before your inner for
loop and thus also won't acquire a number.
see findstr /?
from the prompt for docco...