I tried asking this once, but I think there was some confusion so I'm going to try this fresh. Here is the code:
set regVar=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
set excluded=Microsoft MDOP Dell
set count=0
for /f "tokens=2,*" %%a in ('Reg Query %regVar% /S^|find " DisplayName" ^| findstr /v "%excluded%"') do (
set /a count+=1
setlocal EnableDelayedExpansion
for %%n in (!count!) do (
endlocal
set product[%%n]=%%b
echo %%n.%tab%%%b
echo %%a
)
)
What this does is go through all uninstall registries and then adds each DisplayName key into an array called product[] and then prints the result for the current number it's on i the loop to the screen for a menu. What you can then do is type in the number, and it returns the Display name in that array:
So this as it stands filters out everything microsoft, mdop, and dell
What I want it to do is ALSO look in that key for that DisplayName and return another key called UninstallString and assign that to the array uninstallprod[] with the same associated index. The issue I'm running into is that I cant figure out how to either query using a statement like you can in sql
Select UninstallString from REGISTRY where DisplayName="Program name"
with program name being the string returned from the DisplayName you selected, or to have a SINGLE query that will allow me to both filter out the DisplayNames like you see above and also include the UninstallString value in the same statement. The problem with trying it any other way is I can't filter and do both arrays without it ending up with indexes completely wrong (it'll skip a display name but still assign the uninstallstring because its not letting me filter both)
UPDATE:
At this point I have it pulling back both a DisplayName and Uninstall string, but it's not advancing the counter correctly. In it's current state, it assigns 2 variables, the name of the key (%%a) to use for assigning and comparing what the key is, and the value of the key (%%c) which is either the name of the program or the uninstall path (string) to use for uninstallation later in the script. So what ends up happening is that I end up with a list of skipped numbers because the counter is getting advanced even when there is no displayname being printed to the list. Here is the code I am now working with.
@echo off
set tab=
set regVar=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
set excluded=Microsoft MDOP Dell
set count=1
for /f "tokens=1,2,*" %%a in ('Reg Query %regVar% /S^|findstr "DisplayName UninstallString" ^| findstr /v "%excluded%"') do (
setlocal EnableDelayedExpansion
for %%n in (!count!) do (
endlocal
if "%%a"=="DisplayName" set product[%%n]=%%c&echo %%n.%tab%%%c
if "%%a"=="UninstallString" if defined product[%%n] set uninstall[%%n]==%%c&set/a count+=1
)
)
Just as an example, I have Sublime Text 2.0.1 and 64 bit HP CIO Components Installer on my list. What ends up happening is I get a list like this:
1. Sublime Text 2.0.1
3. 64 bit HP CIO Components Installer
So for some reason the counter is getting advanced past 2 even though no product[2] is being defined. And in the 32 bit version I have 5 entries showing up, one of them is blank, which prints like this:
1. Adobe Flash Player 11 ActiveX
2. Google Chrome
3. TeamViewer 8
4.
4. Google Update Helper.