Tuesday, 8 April 2014

VBScript to Get List of Installed Software through Registry

Description:

Hi, in this article, I am going to write and explain VBScript to Get List of Installed Software through Registry and VBScript code to Find and Export list of Installed Software into CSV file.

Summary:


Get List of Installed Software using VBScript through Registry

1. Copy the below example VBScript code and paste it in notepad or a VBScript editor.
2. Here, I have given the value "." for the variable strComputer, it will takes local computer as source machine. If you want to get list of installed programs from remote computer/remote pc, you can give your computer name.
3. Save the file with a .vbs extension, for example: Get-Installed-Software.vbs
4. Open the command line window (Command Prompt) and run this vbscript file using built-in command line utility CScript
C:\> CScript C:\Scripts\Get-Installed-Softwares.vbs
 Click to get vbscript source code as a file Download Get-Installed-Software.vbs
' Sample VBScript to Get list of Installed Programs through Registry.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
Dim objReg, strSubkey, arrSubkeys 
Dim Name, Version

strComputer = "." 

' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 

Set objReg=GetObject( _ 
    "winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys 

'Enumerate registry keys.
For Each strSubkey In arrSubkeys 
 objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
 If Name <> "" Then 
     objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey,"DisplayVersion",Version
                  WScript.Echo Name&" : "& Version 
                  WScript.Echo "  "
 End If 
Next 

WScript.Echo "Installed Programs listed successfully through Registry using VBScript."
WScript.Quit
This VBScript will display the installed software application's name and version number in output window.

VBScript to Get Installed Program through Registry

Find and Export Installed Software into CSV using VBScript

1. Copy the below example VBScript code and paste it in notepad or a VBScript editor.
2. Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file where you placed and execute this VB Script file. You can give your own file path like "C:\Users\Administrator\Desktop\Installed-Softwares.csv"
3. Save the file with a .vbs extension, for example: Get-Installed-Software-into-CSV.vbs
4. Double-click the VBScript file (or Run this file from command window) to Get Installed Program into CSV file using VBScript.

 Click to get vbscript source code as a file Download Get-Installed-Software-into-CSV.vbs
' Sample VBScript to Export list of Installed Programs into CSV File.
' ------------------------------------------------------
const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
strComputer = "." 

' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 

Dim objReg, strSubkey, arrSubkeys 

Set objReg=GetObject( _ 
    "winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys 

Dim objFSO, objCSVFile

' Create CSV file 
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Here, I have given CSV file path as "Installed-Softwares.csv", this will create Installed-Softwares.csv file
' where you placed and execute this VB Script file. You can give your own file path
' like "C:\Users\Administrator\Desktop\Installed-Softwares.csv"

Set objCSVFile = objFSO.CreateTextFile("Installed-Softwares.csv", _ 
    ForWriting, True)

' Write Software property names as CSV columns(first line)
 objCSVFile.Write "Name,Version,Publisher,Location,Size" 
 objCSVFile.Writeline ' New Line

Dim Name,Version,Publisher,Location,Size

'Enumerate registry keys.
For Each strSubkey In arrSubkeys 
 objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
 If Name <> "" Then 
    objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayVersion", Version
           objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "Publisher",Publisher
           objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "InstallLocation", Location
           objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "EstimatedSize" , Size
  If  Size <> "" Then 
   Size= Round(Size/1024, 3) & " MB" 
  Else 
   Size= "0 MB"
  End If 

           objCSVFile.Write Name &","&Version&","&Publisher&","&Location&","&Size
           objCSVFile.Writeline ' New Line
      End If 
Next 

WScript.Echo "Installed Softwares exported successfully into CSV file through Registry using VBScript."
WScript.Quit

This VBScript will get installed software program's name, version number, publisher name, size and location into CSV file.


Advertisements
Advertisements

No comments:

Post a Comment