[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2981
  • Last Modified:

Simple batch telnet vbs files commands to be embedded via Visual Basic

Hi,

I have 15 or more vb script files like one attached as example.
What i want to do is instead of clicking each vbs files to telnet, i want to have a nice visual basic program with either dropdown menu or list and command button to execute the telnet commands which do exactly the same as the attached .vbs code.

Simple isnt it :) ......... (For gurus it must be, but for me its like climbing a mountain)

Regards,
aejaz
Set oShell = CreateObject("WScript.Shell")
    'Start up command prompt
    oShell.run"cmd.exe"
    WScript.Sleep 500
    'Send keys to active window; change the 
    '     ip address as needed.
    oShell.SendKeys"telnet 192.168.1.1"
    'Emulate the enter key
    oShell.SendKeys("{Enter}")
    WScript.Sleep 1000
    'write the pass name to the cmd window
    oShell.SendKeys"xyz"
    oShell.SendKeys("{Enter}")
    WScript.Sleep 500
 
    'Exit the program
    'oShell.SendKeys"% "

Open in new window

0
aejaz
Asked:
aejaz
  • 6
  • 3
1 Solution
 
funnyfingersCommented:
Do you know anything about Winsock programming?

You would basically use it to connect verify connection.

Then you would have the drop down and when you click the command button it would use a select case statement and send the command through your connection.  Each time you send a command you will want to verify you are still connected.

Try the tutorials below and let me know if you have any further questions on it.

Tutorials:

http://bytes.com/forum/thread14297.html  <--This is exactly what you want.  In the tutorial you send whatever you put in the textbox.  You can use this sample to add in the combo box and such.
http://www.a1vbcode.com/app-3978.asp
0
 
funnyfingersCommented:
Sorry in that tutorial I think the person forgot to send a carriage return line feed, which is why they are not getting any data returned from the server.

So you would basically add it to the code:

telnet.SendData txtSend.Text & vbCrLf

Again just try it out and let me know if you get stuck.
0
 
funnyfingersCommented:
You can also make a combobox and populate it and then a command button.  Double click on the button and add code similar to this.  This way you can use your existing vbs files.
Select Case combo1.caption
    Case "vbscript1"
        Shell "wscript c:\path\telnetscript1.vbs"
    Case "vbscript2"
        Shell "wscript c:\path\telnetscript2.vbs"
    Case "vbscript3"
        Shell "wscript c:\path\telnetscript3.vbs"
    Case Else
        MsgBox("Unknown")
End Select

Open in new window

0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
aejazAuthor Commented:
Thanks for your email.

Alright, i want to hard code the VBS into visual basic so that i dont direct to the vbs files like c:\test.vbs etc.

I want one exe file which will include all the script embedded. And once the the user click the list item or combo box, it execute the vbs script or connect to telnet n perform automated commands.

Again, i m new to vb, way to new :) . So plz bear with me.
aejaz
0
 
funnyfingersCommented:
When the form loads, you can write out the vbs files to the directory that the exe is run and then still do as above to execute the files:

http://www.vbforums.com/showthread.php?t=342619

Other than that I think it is quite complicated to keep it inside of VB as stated in this post:
http://www.experts-exchange.com/Programming/Misc/Q_22579384.html
0
 
aejazAuthor Commented:
Can u give me simple code which will open cmd prompt, pass telnet command with ip , send password. etc in vb? The first link u provide is not doing this exactly. Ne help?
Regards,
aejaz
0
 
funnyfingersCommented:
Sorry which way are you trying to do this now?  Are you trying the Winsock way or the batch way now?

Also paste what you gotten so far if you don't mind.  Sorry for the late response.
0
 
aejazAuthor Commented:
Kindly see the attached snippet. First thing first, i m getting error "Object required" . To be honest i dont know how this code is working.
Instead of form load, i want a list either in combo or listbox and a command button. Once selected and clicking send button it send the command to the server.

I know its like asking u to write the prog for me :) , i only want startup, rest i will do :)
Regards,
Aejaz
Private Sub Form_Load()
telnet.RemoteHost = "192.168.1.1"
telnet.RemotePort = 23
End Sub
 
Private Sub cmdConnect_Click()
telnet.Connect
cmdConnect.Enabled = False
End Sub
 
Private Sub cmdSendData_Click()
If telnet.State = sckConnected Then
telnet.SendData txtSend.Text
End If
End Sub
 
Private Sub cmdEnd_Click()
telnet.Close
End
End Sub

Open in new window

0
 
funnyfingersCommented:
Oh sorry.  You will have to drag over the WinSock control like you would a button.  In this case you would name that control telnet or change the code and name it winsock1 or whatever.

Go to Project/Components and add the Microsoft Winsock Control.  It should be on your toolbar.  Drag it over to the form, it will be hidden.
0

Featured Post

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.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now