![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | HTA application - trying to use data from text box 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 |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: HTA application - trying to use data from text box 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?"> <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> |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: HTA application - trying to use data from text box Ken wrote: Quote: > 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? > 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> << (hta) get Textbox via element ID Demo >> </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 > 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) |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: HTA application - trying to use data from text box "mr_unreliable" <kindlyReplyToNewsgroup@xxxxxx> wrote Quote: > Hi Ken, > > Here is some code that might help: problem was that in the ShowResults sub, all the ".. contents: " lines were missing line continuation characters. No doubt a news reader issue, right? LFS |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: HTA application - trying to use data from text box "Ken" <kpeterk@xxxxxx> wrote Quote: > 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 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> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| RE: Application Data | .NET General | |||
| Chart text file data | PowerShell | |||
| appdata-local-Application Data-Application Data-Application Data infinitum ad nauseum. WHY | Vista General | |||
| Application Data | Vista performance & maintenance | |||