aejaz
asked on
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
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"% "
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ASKER
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
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
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:
https://www.experts-exchange.com/questions/22579384/embed-exe-inside-another-exe-in-vb.html
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:
https://www.experts-exchange.com/questions/22579384/embed-exe-inside-another-exe-in-vb.html
ASKER
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
Regards,
aejaz
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.
Also paste what you gotten so far if you don't mind. Sorry for the late response.
ASKER
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
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
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.
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.
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.