none
Filter in VBScript "Show all programs" RRS feed

  • Question

  • Hello.

    Here I have a VBScript which shows the installed programs of the local machine in a txt-file with name and versionnumber. What I want is filter some programs, so you don't see them in the txt-file. For example Microsoft Word 2013 and Microsoft Excel 2013.

    Can someone help me with this? See the script below.

    'listapps.vbs
    'Generates a text file listing all 32bit & 64bit apps installed on the local machine
    '===================================================================================
    
    'Declare constants, variables and arrays
    '---------------------------------------
    
    'Registry keys and values
    Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE 
    
    Dim arrKeys(1)
    arrKeys(0) = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    arrKeys(1) = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
    
    strComputer = "." 
    strEntry1a = "DisplayName" 
    strEntry1b = "QuietDisplayName" 
    strEntry2 = "Publisher"
    strEntry3 = "InstallDate"
    strEntry4 = "EstimatedSize"
    strEntry5 = "DisplayVersion"
    
    'Create the output file
    Dim objShell, objShellEnv, strComputerName, objFso
    Set objShell = WScript.CreateObject("WScript.Shell")
    Set objShellEnv = objShell.Environment("Process")
    strComputerName = objShellEnv("ComputerName")
    Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
    Set outputFile = objFso.CreateTextFile(strComputerName & ".txt", True)
    '===================================================================================
    
    Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv") 
    
    'Print header (comment out the line below if you do not want headers in your output file)
    'outputFile.WriteLine"Name" & vbTab & "Publisher" & vbTab & "Installed On" & vbTab & "Size" & vbTab & "Version" & VbCrLf 
    
    For i = 0 to 1
    
      'Check to ensure registry key exists
      intCheckKey = objReg.EnumKey(HKLM, arrKeys(i), arrSubkeys)
    
      If intCheckKey = 0 Then
        For Each strSubkey In arrSubkeys 
          intReturn = objReg.GetStringValue(HKLM, arrKeys(i) & strSubkey, strEntry1a, strValue1) 
    
          If intReturn <> 0 Then 
            objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry1b, strValue1 
          End If 
    
          objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry2, strValue2
          objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry3, strValue3
          objReg.GetDWORDValue HKLM, arrKeys(i) & strSubkey, strEntry4, strValue4
          objReg.GetStringValue HKLM, arrKeys(i) & strSubkey, strEntry5, strValue5
    
        If strValue1 <> "" Then
          outputFile.WriteLine strValue1 & vbTab & strValue2 & vbTab & strValue3 & vbTab & strValue4 & vbTab & strValue5
        End If
    
        Next 
    
      End If
    
    Next 
    
    'Close the output file
    outputFile.Close
    
    'Launch output file for review
    objShell.run "notepad.exe " & strComputerName & ".txt"
    
    'Clean up and exit
    Set objShell = Nothing
    Set objFso = Nothing


    • Edited by Wil_Tim Tuesday, June 9, 2015 6:48 AM title
    Tuesday, June 9, 2015 6:48 AM

Answers

All replies

  • Modify this fragment
        If strValue1 <> ""  then
        outputFile.WriteLine strValue1 & vbTab & strValue2 & . . .
    end if

    like so:    
    If strValue1 <> "" Then
        If InStr(1, strValue1, "Microsoft Office 2013", 1) = 0 _
        Then outputFile.WriteLine strValue1 & vbTab & strValue2 . . .
    End If
    • Proposed as answer by Frederik Long Friday, June 19, 2015 9:38 PM
    Tuesday, June 9, 2015 7:49 AM
  • I recommend contacting the author of your script for help.  This forum can answer specific questions but it cannot fix third party scripts.

    \_(ツ)_/

    Tuesday, June 9, 2015 7:49 AM
  • As noted, this forum is for specific questions rather than "will someone fix this for me".

    As an aside, I wrote a PowerShell script that is probably better than the above:

    Windows IT Pro: Auditing 32-Bit and 64-Bit Applications with PowerShell

    Before you ask: No, you do not need to have PowerShell installed on every computer. You only need PowerShell on the computer on which you run the script.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 9, 2015 2:01 PM
    Moderator