Dynamic application detection with Lite Touch, Revisited

Over a year ago, I posted a blog entry at https://blogs.technet.com/mniehaus/archive/2008/09/25/dynamic-application-detection-with-lite-touch.aspx with details on how to automatically detect installed applications during a Lite Touch deployment, enabling those to be pre-selected when the application list is presented.  Due to changes in the XML file schemas, this script needs some updates for MDT 2010 to be truly “correct”.  The updated script follows, showing how to create a user exit that leverages the ZTIConfigFile script to enumerate all the available (enabled, visible) applications.

Option Explicit

Function UserExit(sType, sWhen, sDetail, bSkip)

    Dim oScriptFile
    Dim oXMLApps, dAllApps
    Dim sGUID
    Dim oNode, oKey
    Dim sValueName, sKey, sValue
    Dim oApplications

    ' Only do this before processing the rule contents

    If sWhen <> "BEFORE" then
        UserExit = Success
        Exit Function
    End if

    ' Make sure ZTIConfigFile is loaded

    On Error Resume Next
    Set oScriptFile = oFSO.OpenTextFile(oUtility.ScriptDir & "\ZTIConfigFile.vbs", 1, false)
    ExecuteGlobal oScriptFile.ReadAll
    On Error Goto 0

    ' Load the applications XML File

    Set oXMLApps = new ConfigFile
    oXMLApps.sFileType = "Applications"
    Set dAllApps = oXMLApps.FindItems

    ' Enumerate the applications

    For each sGUID in dAllApps

        Set oNode = dAllApps(sGUID)

        ' Retrieve the uninstall key node if present

            Set oKey = oNode.selectSingleNode("UninstallKey")

        ' If one was specified, look for the key in the registry

        If not (oKey is nothing) then

            ' Get the key name

            sKey = oKey.Text

            ' Check if the registry key exists by looking for well-known values

            For each sValueName in Array("DisplayName", "UninstallString", "QuietUninstallString")

                sValue = empty
                On Error Resume Next
                sValue = oShell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\" & sKey & "\" & sValueName)
                On Error Goto 0

                If IsEmpty(sValue) then
                    On Error Resume Next
                    sValue = oShell.RegRead("HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & sKey & "\" & sValueName)
                    On Error Goto 0
                End if

                ' If a value was found, add the application's GUID to the list so it gets pre-selected by the wizard

                If not IsEmpty(sValue) then

                    oLogging.CreateEntry "Uninstall registry key found for application " & oNode.selectSingleNode("Name").Text & ", application is present and will be reinstalled.", LogTypeInfo

                    ' Add the GUID if it doesn't already exist in the list

                    Set oApplications = oEnvironment.ListItem("Applications")
                    If not oApplications.Exists(oNode.Attributes.getNamedItem("guid").value) then
                        oApplications.Add oNode.Attributes.getNamedItem("guid").value, ""
                        oEnvironment.ListItem("Applications") = oApplications
                    End if

                    Exit For

                End if

            Next
        Else

            oLogging.CreateEntry "UninstallKey not specified for application " & oNode.selectSingleNode("Name").Text, LogTypeInfo

        End if

    Next

    UserExit = Success

End Function

The code has been updated some, but the concepts haven’t, so if you need more details on what this does check out the original article.