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

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.