Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Batch - Collecting Installed software

- - - - -

  • Please log in to reply
20 replies to this topic

#1
twig123

twig123

    Advanced Member

  • Member
  • PipPipPip
  • 325 posts
  • Joined 02-October 05
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


How to remove advertisement from MSFN

#2
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
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.
--== Scr1ptW1zard ==--

#3
twig123

twig123

    Advanced Member

  • Member
  • PipPipPip
  • 325 posts
  • Joined 02-October 05
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:

#4
twig123

twig123

    Advanced Member

  • Member
  • PipPipPip
  • 325 posts
  • Joined 02-October 05
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:

#5
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,253 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
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.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#6
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag
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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#7
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,253 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag

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 ;)).
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#8
twig123

twig123

    Advanced Member

  • Member
  • PipPipPip
  • 325 posts
  • Joined 02-October 05

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?

#9
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,579 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#10
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
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.
--== Scr1ptW1zard ==--

#11
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,579 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

Attached Files



#12
twig123

twig123

    Advanced Member

  • Member
  • PipPipPip
  • 325 posts
  • Joined 02-October 05
@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...

#13
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,579 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

@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!

Attached Files



#14
bhuvan

bhuvan
  • Member
  • 1 posts
  • Joined 15-March 12
  • OS:none specified
  • Country: Country Flag
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

#15
crobertson

crobertson

    Newbie

  • Member
  • 11 posts
  • Joined 14-December 06
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.

#16
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
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.
--== Scr1ptW1zard ==--

#17
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,435 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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.

Attached Files




GunSmokingMan



#18
iamtheky

iamtheky

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 11-November 08
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.

Attached Files


Edited by iamtheky, 23 May 2012 - 01:33 PM.

iamtheKy

#19
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag
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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#20
iamtheky

iamtheky

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 11-November 08
Thats badass fiend
iamtheKy

#21
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users