home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / vbscript / logon.mac < prev   
INI File  |  2002-02-28  |  6KB  |  151 lines

  1. [PCOMM SCRIPT HEADER]
  2. LANGUAGE=VBSCRIPT
  3. DESCRIPTION=Sample to start a session and logon
  4. [PCOMM SCRIPT SOURCE]
  5.  
  6. '  This sample will start an emulator session and logon to VM.
  7. '  This sample is written assuming the following sequence of host screens
  8. '         MSG10 screen
  9. '         a logon screen containing
  10. '              "USERID   ===> " for the user id input
  11. '              "PASSWORD ===> " for the password input
  12.  
  13. connection_name     = "Z"            '  short name of the session to be created
  14. profile_name        = "RUI"          '  profile that is used to start new session
  15. host_name           = "HOST"         '  the host name
  16. user_id             = "USERID"       '  user id
  17. password            = "PASSWORD"     '  user's password
  18.  
  19. '  much of the logic of this sample is based on loops waiting for some
  20. '  asynchronous event.
  21. '     i  = 0
  22. '     While (NOT asynchronous_condition) And i < number_of_retries
  23. '       i = i + 1
  24. '       autECLSession.autECLPS.Wait(miliseconds_to_wait)
  25. '     Wend
  26. '  where asynchronous_condition is just some boolean asynchronous event
  27.  
  28. '  The following two variables control the
  29. '  number of retries and the number of miliseconds between each retry.
  30.  
  31. number_of_retries   = 1000
  32. miliseconds_to_wait = 500
  33.  
  34. '  determine if there is already a connection with this name
  35.  
  36. set dis_object = autECLConnMgr.autECLConnList.FindConnectionByName(connection_name)
  37.  
  38. '  No connection with this name
  39. If dis_object is NOTHING Then
  40.  
  41. '  start a connection
  42.    autECLConnMgr.StartConnection "profile=" & profile_name & " connname=" & connection_name
  43.  
  44. '  must do a refresh to update the connection list
  45.    autECLConnMgr.autECLConnList.Refresh
  46.  
  47. '  find the connection that was just created
  48.    set dis_object = autECLConnMgr.autECLConnList.FindConnectionByName(connection_name)
  49.  
  50. '  set to use that connection
  51.    autECLSession.SetConnectionByName(connection_name)
  52.  
  53.    i  = 0
  54.    While (dis_object is NOTHING) And i < number_of_retries
  55.      i = i + 1
  56.      autECLSession.autECLPS.Wait(miliseconds_to_wait)
  57.  
  58. '    must do a refresh to update the connection list
  59.      autECLConnMgr.autECLConnList.Refresh
  60.  
  61. '    find the connection that was just created
  62.      set dis_object = autECLConnMgr.autECLConnList.FindConnectionByName(connection_name)
  63.    Wend
  64.  
  65. '  if the connection does not exist then end
  66.    If dis_object is NOTHING Then
  67.       MsgBox("error creating session   " & connection_name)
  68.  
  69. '  The connection exists
  70.    Else
  71.  
  72. '     make sure session is started
  73.       i  = 0
  74.       While (NOT autECLSession.Started) And i < number_of_retries
  75.         i = i + 1
  76.         autECLSession.autECLPS.Wait(miliseconds_to_wait)
  77.       Wend
  78.  
  79. '     session is started
  80.       If autECLSession.Started Then
  81.  
  82. '        start communication for the session and wait for the connection to be established
  83.          If autECLSession.CommStarted Then
  84.          Else
  85.             autECLSession.StartCommunication
  86.             autECLSession.autECLPS.Wait(miliseconds_to_wait)
  87.             i  = 0
  88.             While (NOT autECLSession.CommStarted)  And i < number_of_retries
  89.               i = i + 1
  90.               autECLSession.autECLPS.Wait(miliseconds_to_wait)
  91.             Wend
  92.          End If
  93.  
  94.          If autECLSession.CommStarted Then
  95. '            The connection is established
  96.  
  97. '            proceed to logon screen
  98.              autECLSession.autECLPS.SendKeys(host_name& "[Enter]")
  99.  
  100. '            wait for the logon screen to appear
  101.              found_string = autECLSession.autECLPS.SearchText("RUNNING   " & host_name)
  102.              i = 0
  103.              While (NOT found_string) And i < number_of_retries
  104.                i = i + 1
  105.                autECLSession.autECLPS.Wait(miliseconds_to_wait)
  106.                found_string = autECLSession.autECLPS.SearchText("RUNNING   "& host_name)
  107.              Wend
  108.  
  109.              If found_string Then
  110. '               the logon screen is present
  111.  
  112. '               have to refresh the presentation space
  113.                 autECLSession.autECLPS.autECLFieldList.Refresh
  114.  
  115. '               find where to input the user id
  116.                 set userid_field = autECLSession.autECLPS.autECLFieldList.FindFieldByText("USERID   ===> ", 1, 1, 1)
  117.                 If userid_field is NOTHING then
  118. '                  could not find the place for userid
  119.                    ' Text not found
  120.                    MsgBox ("userid Not Found")
  121.                 Else
  122. '                  input the user id
  123.                    autECLSession.autECLPS.SetText user_id,userid_field.EndRow, userid_field.EndCol+2
  124.  
  125. '                  find the place to put the password
  126.                    set password_field = autECLSession.autECLPS.autECLFieldList.FindFieldByText("PASSWORD ===> ", 1, 1, 1)
  127.                    If password_field is NOTHING then
  128. '                     count not find place for password
  129.                       MsgBox ("password Not Found")
  130.                    Else
  131. '                     input password and send ENTER
  132.                       autECLSession.autECLPS.SetText password,password_field.EndRow, password_field.EndCol+2
  133.                       autECLSession.autECLPS.SendKeys("[Enter]")
  134.                    End If
  135.                 End If
  136.              Else
  137.                 MsgBox(" could not connect to " & host_name & i)
  138.              End If
  139.          Else
  140.              MsgBox(" The connection could not be established ")
  141.          End If
  142.       Else
  143.           MsgBox(" not started "& i)
  144.       End If
  145.    End If
  146.  
  147. '  The connection already exists
  148. Else
  149.    MsgBox("Session  " & connection_name & " already exists ")
  150. End If
  151.