• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
Sign in to follow this  
Followers 0
twig123

Batch - Collecting Installed software

21 posts in this topic

Hey all,

I'm trying to make my batch file gather the installed Applications, and I need some help trying to filter and sort the data. Here is what I have so far:

Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S>c:\temp\installedsoftware.txt
FOR /f "tokens=3 delims= " %%a in ('find "DisplayName REG_SZ" c:\temp\installedsoftware.txt') do Echo %%a>>C:\temp\newsoft.txt

I need to filter out all of the Windows Updates and Security Patches and junk... and then sort the list in Alph. Order.

I botched together some code to filter, but it is very inefficient and maybe someone can improve on it for me:

@Echo Off
Echo.>C:\temp\newsoft.txt
Echo.>C:\temp\newsoft2.txt
Echo.>C:\temp\newsoft3.txt
Echo.>C:\temp\newsoft4.txt
Echo.>C:\temp\newsoft5.txt
Echo.>C:\temp\newsoft6.txt
Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S>c:\temp\installedsoftware.txt
FOR /f "tokens=3 delims= " %%a in ('find "DisplayName REG_SZ" c:\temp\installedsoftware.txt') do Echo %%a>>C:\temp\newsoft.txt
FOR /f "tokens=* skip=3 delims=" %%b in ('find "Microsoft" /v c:\temp\newsoft.txt') do Echo %%b>>C:\temp\newsoft2.txt
FOR /f "tokens=* skip=3 delims=" %%b in ('find "Hotfix" /v c:\temp\newsoft2.txt') do Echo %%b>>C:\temp\newsoft3.txt
FOR /f "tokens=* skip=3 delims=" %%b in ('find "Security Update for" /v c:\temp\newsoft3.txt') do Echo %%b>>C:\temp\newsoft4.txt
FOR /f "tokens=* skip=3 delims=" %%b in ('find "- Software Updates" /v c:\temp\newsoft4.txt') do Echo %%b>>C:\temp\newsoft5.txt
FOR /f "tokens=* skip=3 delims=" %%b in ('find "Update for Windows" /v c:\temp\newsoft5.txt') do Echo %%b>>C:\temp\newsoft6.txt
DEL /Q C:\temp\newsoft.txt
DEL /Q C:\temp\newsoft2.txt
DEL /Q C:\temp\newsoft3.txt
DEL /Q C:\temp\newsoft4.txt
DEL /Q C:\temp\newsoft5.txt
pause

Thanks in advance

0

Share this post


Link to post
Share on other sites

Here's my quick thought on performing this task via batch:


@Echo Off

for /f "tokens=2,*" %%a in ('Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S^|find " DisplayName"') do (
echo %%b|findstr /B /V /C:"Hotfix"|findstr /B /V /C:"Security Update"|findstr /B /V /C:"Update">>.\apps.txt
)
sort .\apps.txt /o .\sorted.txt

You should be careful of what you filter out. I did not filter out "Microsoft" as you did in your post, since that would remove the Microsoft Office products.

0

Share this post


Link to post
Share on other sites

Thanks!

I just tested your code and it works great... except I get an error:

'Hauspie' is not recognized as an internal or external command, operable program or batch file.

...The code finishes and it gathers all the data and sorts it, so I am at a loss for where this is coming from. On top of that, I don't even have anything installed called 'Hauspie' ... :huh:

0

Share this post


Link to post
Share on other sites

Ahh... searched that key and found that the name has a '&' in the name.

Now to figure out how to modify the code to accommodate the symbol... :unsure:

0

Share this post


Link to post
Share on other sites

Vbscript for enumerating hotfixes installed, output to a tab-delimited file that can be opened in Excel:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\TEMP\installedhotfixes.txt", True)
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colQuickFixes = objWMIService.ExecQuery _
("SELECT * FROM Win32_QuickFixEngineering")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "FixComments" & vbtab & _
"HotFixID" & vbtab & "Install Date" & vbtab & _
"InstalledBy" & vbtab & "InstalledOn" & vbtab & _
"Name" & vbtab & "ServicePackInEffect"

For Each objQuickFix in colQuickFixes
objTextFile.WriteLine objQuickFix.Caption & vbtab & _
objQuickFix.Description & vbtab & _
objQuickFix.FixComments & vbtab & _
objQuickFix.HotFixID & vbtab & _
objQuickFix.InstallDate & vbtab & _
objQuickFix.InstalledBy & vbtab & _
objQuickFix.InstalledOn & vbtab & _
objQuickFix.Name & vbtab & _
objQuickFix.ServicePackInEffect

Next
objTextFile.Close

VBScript for enumerating software installed, output to a tab-deliminted file that can be opened in Excel:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\TEMP\installedsoftware.txt", True)
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
& "Version"

For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version

Next
objTextFile.Close

I separated them, because the hotfix one can take some time to run (whereas the software one runs very quickly). You could, however, easily merge them into one larger vbscript and run them as functions, for instance.

0

Share this post


Link to post
Share on other sites

I think this is done a LOT better in other ways too (not batch) i.e. vbscript/jscript or even powershell (exporting a list of this to a HTML page would be a one-liner). But the Win32_Product class is very slow as it starts the windows installer engine... Reading directly from the registry is probably a lot quicker.

0

Share this post


Link to post
Share on other sites
I think this is done a LOT better in other ways too (not batch) i.e. vbscript/jscript or even powershell (exporting a list of this to a HTML page would be a one-liner). But the Win32_Product class is very slow as it starts the windows installer engine... Reading directly from the registry is probably a lot quicker.

Well, there are many other ways that are more powerful, as in writing an app in C++ to do this would be most preferable - but Win32_Product and Win32_QuickFixEngineering work fine. I agree though, for a low-hanging fruit, powershell is probably the best option - I didn't even think of it (I was in a hurry earlier to eat dinner ;)).

0

Share this post


Link to post
Share on other sites
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\TEMP\installedsoftware.txt", True)
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
& "Version"

For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version

Next
objTextFile.Close

This does not pull all of my installed software...

Ex: I have 7-zip installed and it is not in the list when I run this :unsure:

However, I verified that it IS in the registry in the Uninstall key.

Any ideas?

0

Share this post


Link to post
Share on other sites

Product only provides you with Software which was installed using Windows Installer, the only way I can suggest is to get a listing form the registry uninstall key.

0

Share this post


Link to post
Share on other sites

If you still need a batch script...

Here is the modified version of my previous script that will take into account the "&" sign:


@Echo Off

type nul>.\apps.txt
type nul>.\sorted.txt
for /f "tokens=2,*" %%a in ('Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S^|find " DisplayName"') do (
echo "%%b"|findstr /B /V /C:"Hotfix"|findstr /B /V /C:"Security Update"|findstr /B /V /C:"Update">>.\apps.txt
)

sort .\apps.txt /o .\sorted.txt

But now the output will have quotation marks around every name. With some work, they can be removed also.

0

Share this post


Link to post
Share on other sites

Here's a quickly put together 'compiled' batch file which may help give you a console listing. I've not tested it on all OSes etc. but it was intended to work with a good few.

PS

I've not bothered checking to see how it copes with badly named products, if you've got software using `poison` characters then you may be out of luck with this attempt!

OnMyPC.zip

0

Share this post


Link to post
Share on other sites

@Yzöwl - This seems to pull the listings of my apps (Including the pesky one 7zip for some reason was not found in the previous scripts). I would need it output to a file and sorted, however, I could manage that if you felt like being generous and sharing the source...

0

Share this post


Link to post
Share on other sites

@twig123 I'm sorry for not having responded sooner to your request.

Here is an altered version which hopefully creates a SoftList.log file along side the executable.

Note

This file may take some time to complete on a machine with plenty of installed software, so please be patient!

OnMyPC.zip

0

Share this post


Link to post
Share on other sites

Can u please also help me get other details besides software name like install location/path, install date

i will then filter apps which i dont want. bat script is appreciated

0

Share this post


Link to post
Share on other sites

Scr1ptW1zard

I'm using your little batch script

------------------------------

type nul>.\apps.txt

type nul>.\sorted.txt

for /f "tokens=2,*" %%a in ('Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S^|find " DisplayName"') do (

echo "%%b"|findstr /B /V /C:"Hotfix"|findstr /B /V /C:"Security Update"|findstr /B /V /C:"Update">>.\apps.txt

)

sort .\apps.txt /o .\sorted.txt

-------------------------------

And I have a path variable I'm putting everything in that I'm backing up (includes date and customer's name)

I'm trying to modify this clippet to include the variable %destination% .. I've tried several times but can't seem to make it work.

Any ideas?

This utility collects drivers, files from current users, software keys for windows re-install.

0

Share this post


Link to post
Share on other sites

crobertson,

Are you looking to create a file containing the customer information contained in the variable (%destination%) and the list of installed applications?

If so, perhaps this will work for you:

@Echo off
set destination=%date% - My Customer
type nul>.\apps.txt
type nul>.\sorted.txt
for /f "tokens=2,*" %%a in ('Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S^|find " DisplayName"') do (
echo "%%b"|findstr /B /V /C:"Hotfix"|findstr /B /V /C:"Security Update"|findstr /B /V /C:"Update">>.\apps.txt
)

sort .\apps.txt /o .\sorted.txt
echo %destination%>.\destination.txt
>nul copy .\destination.txt+.\sorted.txt .\backup.txt

If this is not correct, please rephrase your question to explain exactly what you are looking for.

0

Share this post


Link to post
Share on other sites

Here is a script that enumerates the unistall keys in the registry, it produces a text file.

Save As ReadRegisteryInstallApps.vbs


Const HKLM = &H80000002
Dim StrComputer :StrComputer = "."

Dim Act :Set Act = CreateObject("WScript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Key :Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Dim Reg :Set Reg = GetObject("winmgmts://" & StrComputer & _
"/root/default:StdRegProv")
Dim Arr :Arr = Array( _
"DisplayName", "QuietDisplayName", "InstallDate", _
"VersionMajor", "VersionMinor","EstimatedSize")

Dim Ts, Txt

Txt = Act.SpecialFolders("Desktop") & "\InstallApplications.txt"
Set Ts = Fso.CreateTextFile(Txt)
Reg.EnumKey HKLM, Key, arrSubkeys

Ts.WriteLine vbtab & "List Of Installed Applications"

For Each strSubkey In arrSubkeys
int1 = Reg.GetStringValue(HKLM, Key & strSubkey, Arr(0), str1)
If int1 <> 0 Then Reg.GetStringValue HKLM, Key & strSubkey, Arr(1), str1
If Not IsNull(str1) Then
Ts.WriteLine _
"----------------------------------------------------------------" & _
vbCrLf & "Item Name " & vbTab & str1
End If
Reg.GetStringValue HKLM, Key & strSubkey, Arr(2), str2
If Not IsNull(str2) Then
Ts.WriteLine "Install On " & vbTab & str2
End If
Reg.GetDWORDValue HKLM, Key & strSubkey, Arr(3), str3
Reg.GetDWORDValue HKLM, Key & strSubkey, Arr(4), str4
If Not IsNull(str3) Then
Ts.WriteLine "Version " & vbTab & str3 & "." & str4
End If
Reg.GetDWORDValue HKLM, Key & strSubkey, Arr(5), str5
If Not IsNull(str5) Then
Ts.WriteLine "File Size " & vbTab & Round(str5/1024, 3) & " MB"
End If
Next
Ts.Close
'-> Open Text Report
Act.Run(Txt),1,True
'-> Ask To Keep Or delete File
If MsgBox("Would you like to keep this file?" & vbCrLf & _
Txt, 4132,"Yes To Keep, No To Delete File?") = 7 Then
Fso.DeleteFile Txt,True
End If

Rename ReadRegisteryInstallApps.vbs.txt to ReadRegisteryInstallApps.vbs to make active.

ReadRegisteryInstallApps.vbs.txt

0

Share this post


Link to post
Share on other sites

Here's an autoit version with a listview. In the listview there is additional functionality to right click and uninstall a selection (additional snippets are credited in the source). This version also dumps a log.txt with all items in the uninstall key, as some of the other solutions do.

InstalledSoftware.zip

Edited by iamtheky
0

Share this post


Link to post
Share on other sites

Since we've moved on to "not batch" solutions, here's a couple PowerShell quickies:

gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|select DisplayName,DisplayVersion,Publisher,UninstallString|sort DisplayName

This outputs all installed software (and version, publisher, uninstall string) at the console. If you want to save it as a HTML file, try:

gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|select DisplayName,DisplayVersion,Publisher,UninstallString|sort DisplayName|ConvertTo-Html|Out-File C:\some\path\somename.htm

That will generate the same list, format it as a HTML table, and save it to C:\some\path\somename.htm If you want the same list, but saved as a CSV file to open with Excel, try:

gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|select DisplayName,DisplayVersion,Publisher,UninstallString|sort DisplayName|ConvertTo-CSV -NoTypeInformation|Out-File C:\some\path\somename.csv

Note that sometimes Excel needs a bit of help to open CSV files properly. It might think it's fixed width, so if it does then tell it it's comma separated and it'll open fine, with each property in a separate column. You could also have manipulated Excel directly using its COM interface (Excel.Application) to create a real Excel document, assuming Excel is installed.

Finally, if you just want to see it graphically on your screen (using a gridview), try:

gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|select DisplayName,DisplayVersion,Publisher,UninstallString|sort DisplayName|ogv

Quick, easy and flexible.

0

Share this post


Link to post
Share on other sites

Thats badass fiend

Thanks! It's really not that impressive though. It's mainly a matter of having taken time to learn PowerShell (and VBScript a decade before, and batch another decade before that). It's different and it takes time but it really pays off to learn new tools. So much people just don't invest the time, even to learn their current tools decently. I would bet that half the people on this board who still do batch today never even pressed F7 at the console ;) Yep, that's been there for over 20 years.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.