Passing a variable from HTA to VBS

madstylex
madstylex used Ask the Experts™
on
Hi Experts,

I have this script which renames the current computer.
It asks the user to enter a new name for the computer using an InputBox.
How can I change it so that it receives the input from a HTA script (passes the variable).

Please help.

Dim Act, CName, Fso, Key, RegName, Rename1, Rename2, Vbs, Uname 
  
	Set Act = CreateObject("WScript.Shell")
	Set Fso = CreateObject("Scripting.FileSystemObject")
	CName = Act.ExpandEnvironmentStrings("%ComputerName%")
	Uname = Act.ExpandEnvironmentStrings("%UserName%")
	Vbs = Act.ExpandEnvironmentStrings("%Systemdrive%\ChangeComputerName.Vbs")
	Key = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"
	RegName = Act.RegRead(Key & "ComputerName")
   Rename1 = InputBox (Uname & ", please type in the new Computer Name","Change Computer Name",,5500,4800)
			Rename2 = Msgbox ("Did You Want To Change This" & vbCrLf & "Old Name : " & CName &_
			vbCrLf & "To This Name : " & Rename1, 4 + 48,"Rename Confirm")
			If Rename2 = 6 Then  Act.RegWrite Key & "ComputerName", A2 End If
			If Rename2 = 7 Then Q = MsgBox (UName & " Has Cancel The Name Change", 0 + 32,"Cancel") End If
	If Fso.FileExists(Vbs) Then Fso.DeleteFile(Vbs) End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, you can put the code in an HTA, then have a text box and a button on the HTA.  The user enters something, and when the button is clicked, it fires your code (as a Sub procedure).

Regards,

Rob.

Author

Commented:
Hi Rob,

I know that you can put the code in the HTA and fire a sub-routine.
What I want to know is how to pass the text collected from the text box into the sub-routine.

Thanks.
Most Valuable Expert 2012
Top Expert 2014
Commented:
If you have a button in the HTA with something like
<input type="button" name="btn_runcode" id="btn_runcode" value="Run Code" onClick="RunCode">

and you have an input box with something like
<input type="text" name="txt_computername" id="txt_computername">

then in the RunCode procedure that you add to the HTA, you can change this line:
   Rename1 = InputBox (Uname & ", please type in the new Computer Name","Change Computer Name",,5500,4800)

to this
   Rename1 = txt_computername.Value


Regards,

Rob.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial