Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS to HTA Conversion

Posted on 2009-04-13
13
Medium Priority
?
1,416 Views
Last Modified: 2012-06-21
I want to convert the below code to HTA.
dim oshell
strip = Inputbox("Enter the IP Address", "IP Address")
strname=inputbox("Enter the Username", "Username")
strpswd=inputbox("Enter the Password", "Password")
strdesc=inputbox("Enter Description", "Description")
set oshell = Wscript.createobject ("Wscript.shell")
oshell.run "telnet " & strip
oshell.appactivate "Telnet"
Wscript.sleep 100
oshell.appactivate "Telnet " & strip
oshell.sendkeys strname
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys strpswd
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys "interface Serial 0/0/0"
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys "description " & strdesc
oshell.sendkeys "{ENTER}"
set oshell = Nothing

Open in new window

0
Comment
Question by:Dhiraj Mutha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24132950
Here's the basics...ideally for something professional looking, you'd want to modify the gui - adding tables, colors, etc.  There are plenty of sites with html examples, if you don't know html (I'm not strong in that area).

I've included a validate sub to allow you to verify the data input.
For example, you could add a regular expression to ensure that the ip address consists of 3 periods.  You could also test that none of the numbers exceed a valid range, or go above 255...

Same could be done for the other fields.
Have fun!
<html> 
<head>
   <title>telnet script</title>
</head>
 
<script Language="VBScript">
 
Sub Main()
dim oshell
strip = ip.Value
strname=username.Value
strpswd=password.Value
strdesc=desc.value
set oshell = Wscript.createobject ("Wscript.shell")
oshell.run "telnet " & strip
oshell.appactivate "Telnet"
Wscript.sleep 100
oshell.appactivate "Telnet " & strip
oshell.sendkeys strname
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys strpswd
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys "interface Serial 0/0/0"
Wscript.sleep 100
oshell.sendkeys "{ENTER}"
Wscript.sleep 100
oshell.sendkeys "description " & strdesc
oshell.sendkeys "{ENTER}"
set oshell = Nothing
End Sub
 
Sub ValidateDetails()
  'Rules to validate ip.Value, username.Value, password.Value & desc.Value
 
  'Now run 'your' code...
  Main()
End Sub
 
</script>
 
<body>
Enter the IP Address:<input type="text" name="ip"/><br />
Enter the Username:<input type="text" name="username" /><br />
Enter the Password:<input type="text" name="password" /><br />
Enter Description:<input type="text" name="desc" /><br />
<center>
  <input type="button" onClick="ValidateDetails" value="Submit">
</center>
</body>
</html>

Open in new window

0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24134883
Hi, thanks for the update. But this is what i have tried and getting the below error.
Error.jpeg
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24134891
Remove wscript from your code line:
set oshell = Wscript.createobject ("Wscript.shell")

to read:
set oshell =createobject ("Wscript.shell")
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24134956
Now i amd getting the same error on Line # 16.
0
 
LVL 1

Expert Comment

by:kelvinight
ID: 24136036
i think wscript.sleep is not working in HTA, correct me if im wrong
0
 
LVL 1

Expert Comment

by:kelvinight
ID: 24136092
well, i removed all Wscript.sleep 100 lines from sirbunty's post, and it run without error
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24137146
Correct - you cannot use wscript.sleep as it's a method of wsh, not hta.
You could use a timer instead...
However, with 100 ms delays, is it needed?
Try it without:


<html> 
<head>
   <title>telnet script</title>
</head>
 
<script Language="VBScript">
 
Sub Main()
dim oshell
strip = ip.Value
strname=username.Value
strpswd=password.Value
strdesc=desc.value
set oshell = Wscript.createobject ("Wscript.shell")
oshell.run "telnet " & strip
oshell.appactivate "Telnet"
oshell.appactivate "Telnet " & strip
oshell.sendkeys strname
oshell.sendkeys "{ENTER}"
oshell.sendkeys strpswd
oshell.sendkeys "{ENTER}"
oshell.sendkeys "interface Serial 0/0/0"
oshell.sendkeys "{ENTER}"
oshell.sendkeys "description " & strdesc
oshell.sendkeys "{ENTER}"
set oshell = Nothing
End Sub
 
Sub ValidateDetails()
  'Rules to validate ip.Value, username.Value, password.Value & desc.Value
 
  'Now run 'your' code...
  Main()
End Sub
 
</script>
 
<body>
Enter the IP Address:<input type="text" name="ip"/><br />
Enter the Username:<input type="text" name="username" /><br />
Enter the Password:<input type="text" name="password" /><br />
Enter Description:<input type="text" name="desc" /><br />
<center>
  <input type="button" onClick="ValidateDetails" value="Submit">
</center>
</body>
</html>

Open in new window

0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24138130
I will try the above code and you all know about this tomorrow.
0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24141627
The code is working without any errors. But when i try to run the script it opens Telnet 10.10.10.20 and enters the username and password and then stops there. If you manually press enter it does not working it says "Incorrect Password". I think thats why the Sleep command is required. Please check.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24158006
Try this...it'll generate a temporary script file to perform the sleep routine...
<html> 
<head>
   <title>telnet script</title>
</head>
 
<script Language="VBScript">
 
Sub Main()
dim oshell
strip = ip.Value
strname=username.Value
strpswd=password.Value
strdesc=desc.value
set oshell = Wscript.createobject ("Wscript.shell")
oshell.run "telnet " & strip
oshell.appactivate "Telnet"
Wait 100
oshell.appactivate "Telnet " & strip
oshell.sendkeys strname
Wait 100
oshell.sendkeys "{ENTER}"
Wait 100
oshell.sendkeys strpswd
Wait 100
oshell.sendkeys "{ENTER}"
Wait 100
oshell.sendkeys "interface Serial 0/0/0"
Wait 100
oshell.sendkeys "{ENTER}"
Wait 100
oshell.sendkeys "description " & strdesc
oshell.sendkeys "{ENTER}"
set oshell = Nothing
End Sub
 
Sub ValidateDetails()
  'Rules to validate ip.Value, username.Value, password.Value & desc.Value
 
  'Now run 'your' code...
  Main()
End Sub
 
Sub Wait(ms) 
  Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
  If Not objFSO.FileExists("wait.vbs") Then 
    Set objFile = objFSO.CreateTextFile("wait.vbs")
    objFile.WriteLine "wscript.sleep wscript.arguments(0)"
    objFile.Close
  End If
 
  CreateObject("WScript.Shell").Run "wait.vbs " & ms,1 , True
End Sub
 
</script>
 
<body>
Enter the IP Address:<input type="text" name="ip"/><br />
Enter the Username:<input type="text" name="username" /><br />
Enter the Password:<input type="text" name="password" /><br />
Enter Description:<input type="text" name="desc" /><br />
<center>
  <input type="button" onClick="ValidateDetails" value="Submit">
</center>
</body>
</html>

Open in new window

0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24159396
Thanks for the relpy... I will have a check on this and update you ASAP.
0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 24164957
That worked absoultely fine. Only one problem.... it is creating a Wait.vbs file... that should get deleted once i close the HTA is it possible.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 1000 total points
ID: 24166319
1) Move the objFSO declaration from line 44 to the line immediately following the opening script tag <script>.

2) Just after line 33 (line 34), enter the following line (line 34, the End Sub line will become line 35).

    If objFSO.FileExists("wait.vbs") Then objFSO.DeleteFile "wait.vbs"

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question