如何在HTA中显示数组列表中的数据

时间:2012-10-23 00:38:10

标签: vbscript hta

我有一个VBScript脚本,用于检查计算机中是否安装了一组软件(如果已安装)我只想在HTA中显示。

但我在HTA中显示有关信息的问题。我该如何解决?

以下是代码:

<html>
    <head>
        <title>Uninstall</title>
        <HTA:APPLICATION
            APPLICATIONNAME="Script Command Center"
            ID="oInstall"
            VERSION="1.0"
            SCROLL = "yes"
            Icon=""
            SINGLEINSTANCE="no"
            WINDOWSTATE="fixed"
        />
    </head>

    <SCRIPT Language = "VBScript">
        Const adVarChar = 200
        Const MaxCharacters = 255
        Set DataList = CreateObject("ADOR.Recordset")

        Sub Subroutine1
            DataArea.InnerHTML = "Searching ...... please wait"
            document.body.style.cursor = "wait"
            idTimer = window.setTimeout("Subroutine2", 2000, "VBScript")
        End Sub

        Sub Subroutine2
            window.clearTimeout(idTimer)
            On Error Resume Next
            Dim strAnswere
            Const HKEY_LOCAL_MACHINE = &H80000002
            Set WshShell = CreateObject("WScript.shell")
            AppList = Array("Torrent","Toshiba", "Java")
            For Each AppName in AppList
                'WSCript.Echo "Searching for keyword: " & AppName
                'First, find the GUID
                strComputer = "."
                Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
                strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
                objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys,strName

                For Each subkey In arrSubKeys
                    InstalledAppName = ""
                    InstalledAppName = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")
                    InstalledAppVersion = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\DisplayVersion")
                    'Wscript.Echo InstalledAppName
                    If InStr(1,InstalledAppName,AppName,1) > 0 Then
                        strName = InstalledAppName
                        DataList("SoftwareName") = strName

                        RawGUID = ""
                        GUID = ""
                        RawGUID = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\UninstallString")
                        GUID = Mid(RawGUID, instr(RawGUID, "{"), 38)
                        'WSCript.Echo GUID
                        If GUID<>"" Then
                            strAnswere = MsgBox("Do you want to Uninstall " & AppName & " Version " & InstalledAppVersion &" ? ", vbYesNoCancel, "Uninstaller")
                            If strAnswere = vbYes Then
                                WshShell.Run "msiexec /x " & GUID & " /q"
                            ElseIf strAnswere = vbCancel Then
                                Wscript.Echo "Cancel was clicked... Quitting."
                                Wscript.Quit
                            ElseIf strAnswere = vbNo Then
                                WScript.Echo "The App still install"
                                DataArea.InnerHTML = strHTML
                                DataList("SoftwareName") = strName
                                DataList.Fields.Append "SoftwareName", adVarChar, MaxCharacters
                                DataList.Fields.Append "Vendor", adVarChar, MaxCharacters
                                DataList.Fields.Append "Version", adVarChar, MaxCharacters
                                DataList.Fields.Append "UninstallString", adVarChar, MaxCharacters
                                DataList.Open

                                strHTML = "<form name=""softwareform"" method=""post"">" & _
                                          "<table class=""softwaretable"">" & _
                                          "<tr>" & _
                                              "<th style=""width:30%;text-align:left;cursor:hand;"" " & _
                                                  "title=""Sort by Software Title"" onClick=SortSoftwareItems(1)>" & _
                                                  "Software Title&nbsp;&nbsp;&nbsp;^</th>" & _
                                              "<th style=""width:24%;text-align:left;cursor:hand;"" " & _
                                                  "title=""Sort by Vendor"" onClick=SortSoftwareItems(2)>Vendor</th>" & _
                                              "<th style=""width:15%;text-align:left;cursor:hand;"" " & _
                                                  "title=""Sort by Version"" onClick=SortSoftwareItems(3)>Version</th>" & _
                                              "<th style=""width:8%;"">&nbsp;</th>" & _
                                              "<th style=""width:8%;"">&nbsp;</th>" & _
                                          "</tr>"
                            End If
                            Exit For
                        End If
                    End If
                Next
                If subkey = "" Then
                    WScript.Echo "no"
                End If
            Next
        End Sub
    </SCRIPT>

    <body>
        <h1 style="text-align:center">uninstall</h1>
        <input type="button" value="Count Events" onClick="Subroutine1"><p>

        <span id=SoftwareNameArea></span>
        <span id=SoftwareVersionArea></span>
        <br /><br />

        <div id="DataArea"></div>
    </body>
</html>

0 个答案:

没有答案