Link to home
Start Free TrialLog in
Avatar of vithal_m
vithal_m

asked on

VBScript Required. Script to query registry on all PCs in Domain and report back all installed software.

Hello Experts,

Iam in urgent need of a VBScript that can query registry on all computers in the domain and then report back the following in a .csv or which ever is the best way to record such large amount of data. If we can also include the ability to choose the OUs as an option that would be great.

I am looking at other scripts from Rob but it looks like it doesnt suit my requirements..

example. "Domain Inventory.csv"

Column1              Column2
Computer name: %name%
Logged user: %username%
Installed Apps: %Apps%

Happy to provide more info.
Avatar of zoofan
zoofan
Flag of United States of America image

I wrote this one about a year ago, does do what you need?

grabs all apps listed in uninstall key from the registry(basically everything in add/remove)
is feed from a txt file list of pc names.
and outputs to a csv file.

https://www.experts-exchange.com/questions/22735065/Getting-all-installed-apps-from-add-remove-programs-of-remote-computers-into-excel.html




zf
The code.





zf
'===Start copy: getapps.vbs===
' ---------------------------------------------------------------'
' getappversions.vbs
' 'Sample VBScript to query remote computers
' 'and return versions for word and excel.
' ''Author Riley C. aka ZooFan
' '''Version 2.9 - August 2007
' ''''www.experts-exchange.com question ID: 22735065
' ---------------------------------------------------------------'
'
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3 'FileObject Access Type
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 'FileObject Format Type
Dim objFso
Dim objWshshell
Dim objOutputFile
Dim strCurPath
Dim dte
Dim tme
Dim arrPCnames()
Dim intPCLoop      
Dim strNewFile
Dim strPCFile
Dim objPCOutputFile
      Set objFso = CreateObject("Scripting.FileSystemObject")
      Set objWshshell = WScript.CreateObject("WScript.Shell")
      strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
      dte = Replace(FormatDateTime(date(),vbshortdate),"/","-")
      tme = Replace(Replace(FormatDateTime(now(),vbLongtime),":","-")," ","")
      strNewFile = strCurPath & "\" & tme & "_" & dte & ".csv"
      strPCFile = InputBox("Please enter the full path and file" & VbCrLf & "name of the file with the computer names.","Get application versions from remote computers..")
            If Not objFso.FileExists(strPCFile) Then
                  MsgBox "You must enter a valid full path and file name!",vbOKOnly,"Get application versions from remote computers.."
                WScript.Quit(0)
            Elseif strPCFile = "" Then
                  MsgBox "You must enter a filename!",vbOKOnly,"Get application versions from remote computers.."
                WScript.Quit(0)
            Else
            Call createoutputfile(strNewFile)
            Call readpclist(strPCFile)
            Set objOutputFile = objFso.OpenTextFile(strNewFile,ForWriting,TristateUseDefault)
                  objOutputFile.WriteLine("Computer,Apps List")
                                                 For intPCLoop = LBound(arrPCnames) To UBound(arrPCnames)
                                                objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & InstalledApps(arrPCnames(intPCLoop)))
                                                Next
                              objOutputFile.Close                                                
                  MsgBox "File has been processed, and results saved in " & strNewFile ,vbOKOnly,"Get application versions from remote computers."      
            End If
      WScript.Quit(0)                                    
Sub readpclist(strPcList)
Dim objPCnames
Dim objReadFile
Dim intLneCount
      Set objPCnames = objFso.GetFile(strPCFile)
      Set objReadFile = objPCnames.OpenAsTextStream(ForReading, TristateUseDefault)
            Do Until objReadFile.AtEndOfStream
                  ReDim Preserve arrPCnames(intLneCount)
                  arrPCnames(intLneCount) = objReadFile.ReadLine
                  intLneCount = intLneCount + 1
            Loop
      objReadFile.Close
End sub                                    
Sub createoutputfile(strNewFileName)
            If objFso.FileExists(strNewFileName) Then
                  objFso.deleteFile(strNewFileName)
            Else
                  Set objOutputFile = objFso.CreateTextFile(strNewFileName)
                  objOutputFile.Close      
            End If
End Sub
Function InstalledApps(strPcName)
Dim appsFile
Dim strRegValue
Dim strKey
Dim intRegTest
Dim strBaseKey
Dim arSubKeys()
Dim strValue
Dim iErr
Dim iErr2
Dim testConn
Dim errMess
 Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
 On Error Resume Next
      Set testConn = GetObject("winmgmts:\\" & strPcName,"Root\CIMV2")
      iErr = Hex(Err.Number)
      Select Case Ucase(iErr)
          Case "1AD"
                         Set strRegValue = GetObject("winmgmts://" & strPcName & "/root/default:StdRegProv")
                         iErr2 = Hex(Err.Number)
                               Select Case Ucase(iErr2)
                                     Case "1AD"
                                           strBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
                                           intRegTest = strRegValue.EnumKey(HKLM, strBaseKey, arSubKeys)
                                          For Each strKey In arSubKeys
                                                intRegTest = strRegValue.GetStringValue(HKLM, strBaseKey & strKey, "DisplayName", strValue)
                                                      If intRegTest <> 0 Then
                                                            strRegValue.GetStringValue HKLM, strBaseKey & strKey, "QuietDisplayName", strValue
                                                      End If
                                                      If strValue <> "" Then
                                                            InstalledApps = InstalledApps & strValue & ","
                                                      End If
                                          Next
                                    Case Else
                                          InstalledApps = Err.Description      
                              End Select
                  Case Else
                        InstalledApps = Err.Description
            End Select
 
End Function
'===End copy: getapps.vbs===

Open in new window

would be happy to modify it to better suit if need be.



zf
Avatar of vithal_m
vithal_m

ASKER

Hello Zoofan,

Thanks for the quick reply.

does this code grab only Windows Installer based apps or all installed apps?

thanks,
VM
Grabs all apps listed/registered in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

so both.


zf
ASKER CERTIFIED SOLUTION
Avatar of zoofan
zoofan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the reply.

I would like to exclude Hotfixes from this list. is it possible?

thanks,VM
As there is no common key(element) that will cover ALL hot fixes, about the only thing I could do for that would be to exclude everything that starts with KB(knowledge Base) XXXXXXX from the list.

zf
that would be great.and also sorry for doing this..can we have some check as an option and exclude servers from the list. just add a pop up button after i input the computers list files. do you wan to exclude server yes or no.

I know that you can use this
ProductType from ("Win32_OperatingSystem") and check if its a server. If ProductType =1 it is a server. it anything else is a workstation or laptop etc..

Thanks heaps.
VM.
I ran the above script and got the following message for the first 70 machines
"The remote server machine does not exist or is unavailable"
I have manually pinged the machines and they respond. Remote registry is enabled.


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was searching on google for something and bumped into this...this script works but the formatting is totally out. This does not have the WMI issue. and WMI is turned on all PCs by default.

' This code developed by Timothy Brigham July 2006.
' Revisions made Oct 2007

' This is designed to be run by an administrator to audit the software installed
' throughout a domain. You will need to adjust the LDAP query to reflect your local
' configuration. You may additionally define OUs to restrict and speed up the search.

' Much of this code collected from various usenet sources.

' Revision 2 - includes logging to a text file

' This is Tim Brigham. Revision 2 of my software audit software is available now,
' including logging to a text file. The default path for the saved audit is
' C:\TimSoftwareAudit.txt, but can be edited by changing the path below.

' Please note that the oContainer item with the LDAP query does not
' need to point to the root of the domain. I use this script frequently
' on specific OUs. The easiest way to do determine the LDAP syntax is to use an
' LDAP browser, such as adsiedit from Microsoft. Simply copy and paste in
' the distinguishedName attribute.

' If you have any questions, please comtact me at timbrigham@gmail.com.

Set fso = CreateObject("Scripting.FileSystemObject")

' **************************************************
' make any changes here to set properties of the audit


Set oContainer=GetObject("LDAP://DC=au,DC=challenger,DC=net")
Set LogFile = fso.CreateTextFile("C:\TimSoftwareAudit.csv", True)

' no changes should be needed under this point
' **************************************************


Dim oContainer

ListComputers oContainer
Set oContainer = Nothing

Sub ListComputers(oObject)
Dim Object
For Each Object in oObject
  If Object.Class = "organizationalUnit" Then
    ListComputers ( Object )
  End If

  If Object.Class = "computer" Then
    Name = Object.Name
    Name = Mid( Name, 4 )

    'WScript.Echo "Computer Name: "
    'WScript.Echo Name

    LogFile.WriteLine("Computer Name:,"+Name)
   ' LogFile.WriteLine(Name)

    On Error Resume Next

    'WScript.Echo "Logged in User(s): "
    UserName = GetUser(Name)
   ' WScript.Echo UserName
    LogFile.WriteLine("Logged in User(s):,"+UserName)
    'LogFile.WriteLine(UserName)


    'WScript.Echo "Installed Applications: " 
    Installed = InstalledApplications(Name)
    'WScript.Echo Installed
    'WScript.Echo ""
    'WScript.Echo ""
    LogFile.WriteLine "Installed Applications"
      LogFile.WriteLine(","+Installed)
   ' LogFile.WriteLine("")
    LogFile.WriteLine("")


  End If
Next

End Sub

Function GetUser( strComputer )
  Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colComputer = objWMIService.ExecQuery _
      ("Select * from Win32_ComputerSystem")
  For Each objComputer in colComputer
      GetUser = GetUser & objComputer.UserName & vblf
  Next
End Function

Function InstalledApplications(node)
 Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
 Set oRegistry = _
  GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
  & node & "/root/default:StdRegProv")
 sBaseKey = _
  "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
 iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
 For Each sKey In arSubKeys
  iRC = oRegistry.GetStringValue( _
   HKLM, sBaseKey & sKey, "DisplayName", sValue)
  If iRC <> 0 Then
   oRegistry.GetStringValue _
    HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
  End If
  If sValue <> "" Then
   InstalledApplications = _
    InstalledApplications & sValue & vbCrLf
  End If
 Next
End Function
Looks to also use WMI


zf