I was wondering if anyone has either a VBScript or JavaScript subroutine that will work in a simple HTA to make sure neither of the two mandatory text boxes [Machine Name (CompID) & Program Name (ProgID)] are blank when the user presses the Click to Find the Program button? I would like it to pop up a warning saying blank fields aren't allowed then just go back to the HTA so they can correct and re-submit (but without displaying the scripting error pop-up I get now).
After a bunch of Googling, I've found some JavaScript validation routines but they all seem to use CSS 2 or 3 form controls that I believe HTA doesn't support (from what I understand, which definitely could be totally wrong). I apologize for my sloppy HTA but this is what I could hack together at this point. Any help would be greatly appreciated.
After a bunch of Googling, I've found some JavaScript validation routines but they all seem to use CSS 2 or 3 form controls that I believe HTA doesn't support (from what I understand, which definitely could be totally wrong). I apologize for my sloppy HTA but this is what I could hack together at this point. Any help would be greatly appreciated.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Program Finder</title>
<script language="VBScript">
Option Explicit
Dim width, height
width = 900 -1
height = 500 -1
self.ResizeTo width, height
self.MoveTo (screen.availWidth - width)/2, (screen.availHeight - height)/2
</script>
<HTA:APPLICATION
APPLICATIONNAME="Product Finder"
Caption="Yes"
MaximizeButton="No"
MinimizeButton="No"
SCROLL="No"
SINGLEINSTANCE="yes"
WINDOWSTATE="Normal"
BORDER="Normal"
Icon=C:\Windows\System32\Magnify.exe
>
</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 & objSoftware.Caption & vbCrLf & _
"Description:" & vbtab & objSoftware.Description & vbCrLf & _
"Identifying #:" & vbtab & objSoftware.IdentifyingNumber & vbCrLf & _
"Install Date:" & vbtab & vbtab & objSoftware.InstallDate2 & vbCrLf & _
"Install Location:" & vbtab & objSoftware.InstallLocation & vbCrLf & _
"Install State:" & vbtab & objSoftware.InstallState & vbCrLf & _
"Name:" & vbtab & vbtab & objSoftware.Name & vbCrLf & _
"Package Cache:" & vbtab & objSoftware.PackageCache & vbCrLf & _
"SKU Number:" & vbtab & objSoftware.SKUNumber & vbCrLf & _
"Vendor:" & vbtab & vbtab & objSoftware.Vendor & vbCrLf & _
"Version:" & vbtab & vbtab & objSoftware.Version)
Next
End Sub
Sub CloseBtn_OnClick
Window.Close
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 a Program:  <text>
<input type="text" name="ProgID" size="30"> <br> <br>
<text>  </text>
<button onclick="FindProg">Click to Find the Program</button>
<Input Type = "Button" Name = "CloseBtn" VALUE = "Close Window">
</body>