I have a script which finds specific installed software but I am having trouble also getting the software’s version. For example, say I am getting a list of all Microsoft software installed. Here is what I have thus far:
echo software installed > software_list.txt
echo ================= >>software_list.txt
reg export HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall temp1.txt
find "Microsoft" temp1.txt| find "DisplayName" > temp2.txt
for /f "tokens=2,3 delims==" %%a in (temp2.txt) do (echo %%a >> software_list.txt)
start notepad "software_list.txt"
del temp1.txt temp2.txt
How can I also get the DisplayVersion from the reg export? If I replace DisplayName with DisplayVersion, nothing is even found. Or, is there another avenue I should be taking here?
Replacing
DisplayNamewithDisplayVersionresults in an empty output because of the way this line works:What this line does is it finds all lines in the
temp2.txtfile that contain both the Microsoft and DisplayName substrings (that is, it finds the products whose names contain Microsoft). The lines with DisplayVersion, in their turn, contain product version numbers and don’t contain the word Microsoft, which is why you get empty output.I can suggest a couple of alternative solutions that use WMI:
Parse the
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstallsubkeys using a script (VBScript, PowerShell etc) rather than a batch file, because scripting languages offer much better support for text manipulation. Here’s a VBScript example that outputs the names and versions of installed Microsoft products (products whose names contain Microsoft, to be more precise):Usage:
If the software you’re interested in is installed by the Windows Installer, you can get info about that software (such as the name, vendor, version etc) by querying the WMI
Win32_Productclass. Thewmicutility lets you do this directly from the command line and batch files. Here’re some examples:Print the names and versions of installed software:
List all installed Microsoft products:
List installed products that have Office in their names:
To save the
wmicoutput to a file, you can use the/outputand (optionally)/formatparameters, e.g.:For more information about the
wmicsyntax, seewmic /?