Batch Telnet procedure and Operation

Source: Internet
Author: User
Tags call shell

Batch Telnet is a remote batch processing task. So how do I set the batch Telnet? Next we will analyze the relevant content. First, we need to understand the initial method.

Two methods can be used to convert bat to EXE

There are two ways to convert bat to EXE, one is to use tools, such as the bat2exe tool under DOS; the other is to use Shell functions in VB, the DOS window is closed after the end of the form is as follows ):

Shell "command.com /c copy c:\1.txt a:\",vbNormalFocus  

How do I run automatic Telnet tasks in batch processing?
 
In general, ftp is very common in batch transaction processing. What if Batch Telnet makes management easier?

Generally, there are two methods:

1. Windows Script Host using VBS)

2. Automatic Terminal Method for some terminals that can be configured with automatic Telnet)

Here we will discuss the first method: The VBS method. Because Windows Script Host comes with the system, we can do it without installing local software. Therefore, it is generally the first choice to solve the problem.

First, we create a script named tel. vbs. Telnet to the cisco router as an example. You can modify the relevant content.

 

Then, create a batch_tel.bat batch file:

 
 
  1. Rem start Telnet
  2. Start Telnet.exe
  3. Rem batch Telnet
  4. Cscript // nologo tel. vbs

Finally, we only need to run batch_tel.bat to easily complete the Telnet work.

For what the SendKeys command can send, we can look at the following list:

 
 
  1. BACKSPACE {BACKSPACE}, {BS}, or {BKSP}  
  2. BREAK {BREAK}  
  3. CAPS LOCK {CAPSLOCK}  
  4. DEL ;or DELETE {DELETE} or {DEL}  
  5. DOWN ARROW {DOWN}  
  6. END {END}  
  7. ENTER {ENTER}or ~  
  8. ESC {ESC}  
  9. HELP {HELP}  
  10. HOME {HOME}  
  11. INS or INSERT {INSERT} or {INS}  
  12. LEFT ARROW {LEFT}  
  13. NUM LOCK {NUMLOCK}  
  14. PAGE DOWN {PGDN}  
  15. PAGE UP {PGUP}  
  16. PRINT SCREEN {PRTSC}  
  17. RIGHT ARROW {RIGHT}  
  18. SCROLL LOCK {SCROLLLOCK}  
  19. TAB {TAB}  
  20. UP ARROW {UP}  
  21. F1 {F1}  
  22. F2 {F2}  
  23. F3 {F3}  
  24. F4 {F4}  
  25. F5 {F5}  
  26. F6 {F6}  
  27. F7 {F7}  
  28. F8 {F8}  
  29. F9 {F9}  
  30. F10 {F10}  
  31. F11 {F11}  
  32. F12 {F12}  
  33. F13 {F13}  
  34. F14 {F14}  
  35. F15 {F15}  
  36. F16 {F16}  
  37.  
  38. SHIFT +  
  39. CTRL ^  
  40. ALT % 

Shell an application and continue running after the program is executed

How to Write Shell & Wait programs? It is hoped that a VB program will use Shell to execute an external program (assumed to be notepad.exe) until the execution of this program ends, and then return to the VB program for further execution, what should I do? When we call Shell, a value is returned. This value is called Process Id. With this Process Id, we can call OpenProcess API to obtain Process Handle, and then use Process Handle to call WaitForSingleObject, you can continue to execute the program that has been executed by Shell. The details are as follows:

1. API declaration:

 
 
  1. Const SYNCHRONIZE = &H100000  
  2. Const INFINITE = &HFFFFFFFF  
  3. Private Declare Function OpenProcess Lib "kernel32" (ByVal  
  4. dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId  
  5. As Long) As Long  
  6. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As  
  7. Long) As Long  
  8. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal  
  9. hHandle As Long, ByVal dwMilliseconds As Long) As Long 

Note: If the preceding statement is placed under "general module", you should remove the Private reserved words before Declare and add the Public reserved words before Const.

2. program example: (using the Notepad program as an example)

 
 
  1. Dim pId As Long and pHnd As Long declare the Process Id and Process Handle variable numbers respectively.
  2. PId = Shell ("Notepad", vbNormalFocus) 'Shell return
  3. Process Id pHnd = OpenProcess (SYNCHRONIZE, 0, pId) 'gets Process Handle
  4. If pHnd <> 0 Then Call WaitForSingleObject (pHnd, INFINITE) 'waits infinitely until the program ends
  5. Call CloseHandle (pHnd)
  6. End If

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.