Pretty new to HTAa. I tried to insert a working VBScript into a simple HTA but it fails with a syntax error pointing to the function line in the VBScript. I've been Googling for hours but can't seem to find an equivalent error being discussed.
Working VBScript:
Here I inserted a slightly modified version into a very basic HTA and it will give a syntax error pointing to the VBScript's Function line when run:
I would appreciate any insight you could provide on why the HTA is rejecting that VBScript and what I could do to fix it.
Working VBScript:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
MySoftware = "Google"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product where Name Like " & CommandLineLike(MySoftware))
For Each objSoftware in colSoftware
x=MsgBox ("Caption" & vbtab & vbtab & vbtab & objSoftware.Caption & vbCrLf & _
"Description" & vbtab & vbtab & objSoftware.Description & vbCrLf & _
"Identifying Number" & vbtab & vbtab & objSoftware.IdentifyingNumber & vbCrLf & _
"Install Date" & vbtab & vbtab & vbtab & objSoftware.InstallDate2 & vbCrLf & _
"Install Location" & vbtab & vbtab & objSoftware.InstallLocation & vbCrLf & _
"Install State" & vbtab & vbtab & objSoftware.InstallState & vbCrLf & _
"Name" & vbtab & vbtab & vbtab & objSoftware.Name & vbCrLf & _
"Package Cache" & vbtab & vbtab & objSoftware.PackageCache & vbCrLf & _
"SKU Number" & vbtab & vbtab & objSoftware.SKUNumber & vbCrLf & _
"Vendor" & vbtab & vbtab & vbtab & objSoftware.Vendor & vbCrLf & _
"Version" & vbtab & vbtab & vbtab & objSoftware.Version)
Next
Function CommandLineLike(MySoftware)
MySoftware = Replace(MySoftware, "\", "\\")
CommandLineLike = "'%" & MySoftware & "%'"
End Function
Here I inserted a slightly modified version into a very basic HTA and it will give a syntax error pointing to the VBScript's Function line when run:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Product Finder</title>
<HTA:APPLICATION
APPLICATIONNAME="Product Finder"
Caption="Yes"
MaximizeButton="No"
MinimizeButton="No"
SCROLL="No"
SINGLEINSTANCE="yes"
WINDOWSTATE="Normal"
BORDER="Thin"
>
</head>
<script language="VBScript">
Option Explicit
sub FindProg
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
MySoftware = ProgID.value
strComputer = CompID.value
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product where Name Like " & CommandLineLike(MySoftware))
For Each objSoftware in colSoftware
x=MsgBox ("Caption" & vbtab & vbtab & vbtab & objSoftware.Caption & vbCrLf & _
"Description" & vbtab & vbtab & objSoftware.Description & vbCrLf & _
"Identifying Number" & vbtab & vbtab & objSoftware.IdentifyingNumber & vbCrLf & _
"Install Date" & vbtab & vbtab & vbtab & objSoftware.InstallDate2 & vbCrLf & _
"Install Location" & vbtab & vbtab & objSoftware.InstallLocation & vbCrLf & _
"Install State" & vbtab & vbtab & objSoftware.InstallState & vbCrLf & _
"Name" & vbtab & vbtab & vbtab & objSoftware.Name & vbCrLf & _
"Package Cache" & vbtab & vbtab & objSoftware.PackageCache & vbCrLf & _
"SKU Number" & vbtab & vbtab & objSoftware.SKUNumber & vbCrLf & _
"Vendor" & vbtab & vbtab & vbtab & objSoftware.Vendor & vbCrLf & _
"Version" & vbtab & vbtab & vbtab & objSoftware.Version)
Next
Function CommandLineLike(MySoftware)
MySoftware = Replace(MySoftware, "\", "\\")
CommandLineLike = "'%" & MySoftware & "%'"
End Function
End Sub
</script>
<body>
<font face=Verdana>
<text>Find out if a program is installed on a remote computer</text> <br> <br>
<text>Machine Name or IP Address:</text>
<input type="text" name="CompID" size="30"> <br> <br>
<text>Partial Name of Program:  <text>
<input type="text" name="ProgID" size="30"> <br> <br>
<button onclick="FindProg">Click to Find the Program</button>
</body>
I would appreciate any insight you could provide on why the HTA is rejecting that VBScript and what I could do to fix it.