×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

HTA fails with Syntax Error when working VBScript inserted

HTA fails with Syntax Error when working VBScript inserted

HTA fails with Syntax Error when working VBScript inserted

(OP)
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 --> VBScript

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 --> HTA

<!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.

RE: HTA fails with Syntax Error when working VBScript inserted

Your function is inside a sub. That's a no-no.

RE: HTA fails with Syntax Error when working VBScript inserted

(OP)
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 --> HTA

<!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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close