Discussion:
HTA application - trying to use data from text box
(too old to reply)
Ken
2009-07-02 12:40:50 UTC
Permalink
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text box and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?

For instance:

Text box: Enter Computer name
Button: Get whatever value was typed in the box and run a script to
find out who is logged into the PC
Ken
2009-07-02 12:44:26 UTC
Permalink
Here's my code so far:

<html>
<head>
<meta http-equiv="Content-Script-Type" content="javascript/vbscript">
<title>-=System Tools=-_-=©2009 Ken Kelly=-</title>

<HTA:APPLICATION
APPLICATIONNAME="System Tools by Ken Kelly"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SINGLEINSTANCE="yes"
NAVIGABLE="yes"
CAPTION="yes"
SCROLL="no"
SYSMENU="yes"
INNERBORDER="no"
BORDER="thin"
BORDERSTYLE="<meta http-equiv=refresh content=300>"
/>


</head>

<SCRIPT Language="VBScript">

Sub Window_onLoad
window.resizeTo 440, 280
End Sub


Sub RunScript1
On Error Resume Next

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

strComputer = InputBox _
("Please enter the name of the computer you want to connect to:",
_
"Enter Computer Name", strLocalComputer)

If strComputer = "" Then
Wscript.Quit
End If

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'wmplayer.exe'")

For Each objProcess in colProcessList
objProcess.Terminate()
Next

End Sub

Sub RunScript2
On Error Resume Next

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

strComputer = InputBox _
("Please enter the name of the computer you want to connect to:",
_
"Enter Computer Name", strLocalComputer)

If strComputer = "" Then
Wscript.Quit
End If

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
Wscript.Echo "User Name = " & objComputer.UserName _
& VBNewLine & "Computer Name = " & objComputer.Name
WScript.Echo objComputer.UserName
Next
End Sub


</SCRIPT>
<SCRIPT FOR="defrag" EVENT="onclick" Language="vbscript">
On Error Resume Next

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

strComputer = InputBox _
("Please enter the name of the computer you want to connect to:",
_
"Enter Computer Name", strLocalComputer)

If strComputer = "" Then
Wscript.Quit
End If

Set objWMIService = GetObject("winmgmts:\\" _
& strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'C:\\'")
For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next
</SCRIPT>

<SCRIPT FOR="whologgedon" EVENT="onClick" LANGUAGE="vbscript">
dim shell
set shell=createobject("wscript.shell")
shell.run "Scripts\whologgedon.vbs"
set shell=nothing
</SCRIPT>

<body bgcolor="#000000" link="#C0C0C0" vlink="#C0C0C0" alink="#C0C0C0"
text="#C0C0C0">
<center>
<P>
<input type="text" name="MyTextBox" size=40 value="Enter PC Name"><p>
<INPUT TYPE=button STYLE="width: 150px" NAME="whologgedon"
VALUE="Who's logged on?">
&nbsp;
<INPUT TYPE=button STYLE="width: 150px" NAME="defrag" VALUE="Defrag
PC">
<input id=runbutton class="button" type="button" value="Find Serial"
name="run_button" onClick="RunScript1">
</P>
</center>
</body>
</html>
acomputerwiz6
2009-07-02 13:36:34 UTC
Permalink
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text box and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
Text box: Enter Computer name
Button: Get whatever value was typed in the box and run a script to
find out who is logged into the PC
Here is a snippet for running from a box


Sub ServiceTag

strComputer = HNBox.value

Set oWMI = GetObject("winmgmts:\\" + StrComputer + "\root\cimv2")
set colitems = oWMI.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
serial.value = objitem.serialnumber
If objitem.serialnumber = vbNul Then
serial.value = "None Found"
End if
Next

End Sub



Comp Name : <input type="text" name="HNbox" size="20"
maxLength="20"><br/>
Mark D. MacLachlan
2009-07-02 21:25:52 UTC
Permalink
I'd recommend you download the HTAHelpOmatic
http://www.microsoft.com/downloads/details.aspx?FamilyId=231D8143-F21B-4
707-B583-AE7B9152E6D9&displaylang=en

It has tons of great examples.

Hope that helps,

Mark D. MacLachlan
HAL07
2009-07-03 06:24:21 UTC
Permalink
Nice to see that more people discover HTA. It's really excellent for making nice GUI's and user-friendly programs.
Too bad Microsoft doesn't do Powershell support for this, but whatever.

I'd like to recommend this webcast for learning HTA:
http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032276555&CountryCode=US
--
-- HAL07, Engineering Services, Norway
Larry Serflaten
2009-07-03 11:41:28 UTC
Permalink
Post by HAL07
Nice to see that more people discover HTA. It's really excellent for making nice GUI's and user-friendly programs.
Too bad Microsoft doesn't do Powershell support for this, but whatever.
http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032276555&CountryCode=US
Having a template set up with the HTA tag and other required elements helps
to quickly get the thing up an running:
http://www.microsoft.com/technet/scriptcenter/guide/sas_sbp_mqxh.mspx

(The above link describes how to create a .vbs template, but it works just as
well for other document files, like .hta)

LFS
mr_unreliable
2009-07-03 00:01:35 UTC
Permalink
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text box and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
Hi Ken,

Here is some code that might help:

--- <code> ---
<HTML>
<HEAD>

<script language="vbscript">
' --- discussion (avoiding that annoying hta "dialog bounce") ---
' this "trick" found on the vbScript ng, code by mikHar, 05Sept06
' Normally, an hta dialog will initially be shown in its "default"
' position and size for a brief instant. Later, when it gets
' around to running your script code, it will move/resize itself
' according to your wishes. Placing the move/resize code AHEAD
' of the hta tag seems to avoid that...
' --- end of discussion ----------------------

Const wdDlg = 500, htDlg = 300 ' dialog size
Const pxLeft = 100, pxTop = 100 ' positioning
window.ResizeTo wdDlg,htDlg
window.MoveTo pxLeft,pxTop
</script>

<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="htaTextBoxIndexingDemo"
WINDOWSTATE="normal" SCROLL = "no" BORDERSTYLE="normal" BORDER="thin"
CAPTION="yes" MAXIMIZEBUTTON="no" MINIMIZEBUTTON="no" ICON="mru.ico"
SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="yes" VERSION="1.0" >

<TITLE> &nbsp;&nbsp; &lt&lt (hta) get Textbox via element ID Demo &gt&gt
</TITLE>

<SCRIPT LANGUAGE="vbScript">
<!--

' --- description block --------------------------
'
' Title: textbox indexing demo, jw 11Mar08
' Author: mr_unreliable
' Website: none at this time (but lurks around the wsh/vbs ng's)
' Usage: Use at you own risk, tested on win98se...
' --- revision history ---------------------------
' 11Mar08: initial attempt (working from "regular" hta dbDlg)...
' --- end of description block -------------------

Option Explicit

' --- global variables ---------------------------
Dim oDoc ' as document object
' --- end of declarations and constants ----------


' --- INITIALIZATION ROUTINE ---------------------

Sub initDialog()
Const sMe = "[initDialog], "

Set oDoc = window.document

' note: dynamically adding textboxes here...
With oDoc.getElementById("inputBoxes")
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox1 type=text
value='the' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox2 type=text
value='quick' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox3 type=text
value='brown' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox4 type=text
value='fox' </input>"
.insertAdjacentHTML "BeforeEnd", "<input id=txtBox5 type=text
value='jumped' </input>"
End With

End Sub

' ------------------------------------------------
' --- EVENT HANDLERS -----------------------------
' ------------------------------------------------

Sub ShowResults()
Const sMe = "[btnClick], "
Dim sResults ' as string

sResults = "txtBox1 contents: " &
oDoc.getElementById("txtBox1").value & vbCrLf _
& "txtBox2 contents: " &
oDoc.getElementById("txtBox2").value & vbCrLf _
& "txtBox3 contents: " &
oDoc.getElementById("txtBox3").value & vbCrLf _
& "txtBox4 contents: " &
oDoc.getElementById("txtBox4").value & vbCrLf _
& "txtBox5 contents: " & oDoc.getElementById("txtBox5").value
MsgBox sResults, vbInformation, " the textbox contents are... "

window.close()
End Sub

//-->
</SCRIPT>
<style>
body {font-family: ms sans serif; font-size: 10pt; font-weight: 400;
color: Navy;
margin-top: 4px; margin-left: 1px; margin-right: 1px;
margin-bottom: 1px;
height: 10px; width: 10px; border-style: none; }

input {width: 400px}
button {height: 25px; width: 100px; font-family: verdana;
font-weight: 400;
width: 125px; }

h4 {position:absolute; top:250; left: 250;
margin-top: 6px; margin-bottom: 0px; padding-top: 0%;
padding-bottom: 0%;
font-family: Arial; font-size: 8pt; font-weight: Normal;
font-style: Italic;
color: Navy; }
</style>
</HEAD>

<BODY onload="initDialog()" scroll='no' text='navy' bgcolor="silver" >

<CENTER>

<DIV id="inputBoxes" >

</DIV>

<BR><BR><BR><BR><BR> <!-- space down a bit to position button -->
<BUTTON id="btnSubmit" onclick="ShowResults()" >Submit</BUTTON>
</CENTER>

<h4 id="logo" ALIGN=RIGHT >&nbsp;jawar productions (all rights
reserved)... </h4>

</BODY>
</HTML>
--- <end code> ---


cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
Larry Serflaten
2009-07-03 09:57:22 UTC
Permalink
Post by mr_unreliable
Hi Ken,
I tried your code, but had to debug it. I forget what all I did, but one major
problem was that in the ShowResults sub, all the ".. contents: " lines were
missing line continuation characters. No doubt a news reader issue, right?

LFS
Larry Serflaten
2009-07-03 11:04:48 UTC
Permalink
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text box and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
Text box: Enter Computer name
Button: Get whatever value was typed in the box and run a script to
find out who is logged into the PC
You have most of it done, the only thing left is to link it all together.
If you include your scripting in the HTA file, you won't need to call out
to other script files. (You still can if you want...)

To link the buttons to their scripts you simply set the 'onClick' value of the
buttons to point to the VBScript Subs you want run. You can get the textbox
contents by naming the textbox in the HTML and using that name in the script.

If you have multiple buttons to run different scripts, put the different scripts in
their own Sub routines and set the button 'onClick' values to point to the
respective Subs for each button.

The example HTA app posted below only has one textbox and one button.
The textbox is named 'user' and the button calls 'RunScript' when clicked.
Note how the 'onClick' value of the button points to RunScript, and
how the contents of the textbox is accessed the the RunScript Sub....

HTH
LFS

------ HTA code from here to end of message ------

<html>
<head>
<title>Link Maker</title>

<SCRIPT Language="VBScript">
' Title: Link Maker
' Author: Larry Serflaten
' Problem: You see a URL in text somewhere and you want to save the target to disk.
' To save it you need it showing as an HTML link so you can right click
' and use the "Save As" context menu item to save the file.
' Usage: Run this HTA, paste the URL into the textbox and press the button.
' The words "The link" are made to point to the entered URL to allow
' saving of the target file.

window.ResizeTo 700, 150
</SCRIPT>

<HTA:APPLICATION
ID="LinkMaker"
APPLICATIONNAME="LinkMaker"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="Normal">
</head>

<SCRIPT Language="VBScript">
Sub RunScript()
link.href = user.value
where.innerhtml = user.value
End Sub
</SCRIPT>

<body>
<a href="about:blank" target="blank" name="link">The link</a href> points to:
<span id="where" style="font-weight:800;">about:blank</span>
</br>

Enter the URL you want linked to, then press the button to change the link:
<input type="text" name="user" size="107">
<input type="button" value="Change Link" onClick="RunScript">
</body>
</html>
t***@jabil.com
2014-04-16 06:46:03 UTC
Permalink
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text area to enter multiple computer name and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
thanks in advance
Evertjan.
2014-04-16 08:47:38 UTC
Permalink
Post by t***@jabil.com
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text area to enter multiple
computer name and then assign buttons to run vbscripts against whatever
is typed into the box. Is this possible?
thanks in advance
I trust Ken is not "kind of new at this" anymore after nearly 5 years,
and is now able to answer his Q with yaes or no. After al he seems to be or
have been a creative person.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dave "Crash" Dummy
2014-04-16 10:16:45 UTC
Permalink
Post by t***@jabil.com
Post by Ken
Hello! I'm kind of new at this but I need a little help. I've created
an HTA application. I'd like to create a text area to enter multiple computer name and then assign
buttons to run vbscripts against whatever is typed into the box. Is
this possible?
thanks in advance
Yes.
--
Crash

Committed to the search for intraterrestrial intelligence.
Loading...