MSFN Forum: Batch - Collecting Installed software - MSFN Forum

Jump to content


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Batch - Collecting Installed software Rate Topic: -----

#1 User is offline   twig123 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 325
  • Joined: 02-October 05

Posted 20 October 2008 - 03:34 PM

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


#2 User is offline   Scr1ptW1zard 

  • Junior
  • Pip
  • Group: Members
  • Posts: 67
  • Joined: 05-July 07

Posted 20 October 2008 - 05:14 PM

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.

#3 User is offline   twig123 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 325
  • Joined: 02-October 05

Posted 21 October 2008 - 01:59 PM

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 User is offline   twig123 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 325
  • Joined: 02-October 05

Posted 21 October 2008 - 04:03 PM

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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,208
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 21 October 2008 - 05:01 PM

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.

#6 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 21 October 2008 - 08:12 PM

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.

#7 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,208
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 22 October 2008 - 12:21 AM

View Postcrahak, on Oct 21 2008, 10:12 PM, said:

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 ;)).

#8 User is offline   twig123 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 325
  • Joined: 02-October 05

Posted 24 October 2008 - 03:39 PM

View Postcluberti, on Oct 21 2008, 07:01 PM, said:

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 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 25 October 2008 - 05:32 AM

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 User is offline   Scr1ptW1zard 

  • Junior
  • Pip
  • Group: Members
  • Posts: 67
  • Joined: 05-July 07

Posted 25 October 2008 - 07:31 PM

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.

#11 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 26 October 2008 - 09:16 AM

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 File(s)



#12 User is offline   twig123 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 325
  • Joined: 02-October 05

Posted 03 November 2008 - 11:22 AM

@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 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 24 November 2008 - 05:03 PM

@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 File(s)



#14 User is offline   bhuvan 

  • Group: Members
  • Posts: 1
  • Joined: 15-March 12
  • OS:none specified
  • Country: Country Flag

Posted 15 March 2012 - 06:50 AM

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 User is offline   crobertson 

  • Newbie
  • Group: Members
  • Posts: 11
  • Joined: 14-December 06

Posted 22 May 2012 - 01:39 PM

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 User is offline   Scr1ptW1zard 

  • Junior
  • Pip
  • Group: Members
  • Posts: 67
  • Joined: 05-July 07

Posted 23 May 2012 - 02:26 AM

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.

#17 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 23 May 2012 - 01:07 PM

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 File(s)



#18 User is offline   iamtheky 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 866
  • Joined: 11-November 08

Posted 23 May 2012 - 01:29 PM

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 File(s)


This post has been edited by iamtheky: 23 May 2012 - 01:33 PM


#19 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 23 May 2012 - 07:44 PM

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.

#20 User is offline   iamtheky 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 866
  • Joined: 11-November 08

Posted 23 May 2012 - 08:17 PM

Thats badass fiend

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy