Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA fails with Syntax Error when working VBScript inserted

Status
Not open for further replies.

bdwilcox

Technical User
Jul 7, 2022
6
0
1
US
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:
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:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<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.
 
Strongm. thank you very much for your help. It was staring me right in the face yet I couldn't see it. Changed the code to pull things out of the sub and got it working with the code:

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">
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("WScript.Shell")
sub FindProg
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

End Sub

Function CommandLineLike(MySoftware)
    MySoftware = Replace(MySoftware, "\", "\\")
    CommandLineLike = "'%" & MySoftware & "%'"
End Function

</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:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<text>
<input type="text" name="ProgID" size="30"> <br> <br>
<button onclick="FindProg">Click to Find the Program</button>
</body>

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top