home *** CD-ROM | disk | FTP | other *** search
/ PCMania 13 / Pcmania_Ep2_13_CD-01.iso / anywhere / DEFAULT / sample.scraw < prev   
Encoding:
Text File  |  2000-10-10  |  67.1 KB  |  1,466 lines

  1. ;  *******************************************************************
  2. ;  *                                                                                        *
  3. ;  *              pcANYWHERE sample script "SAMPLE.SCRAW"              *
  4. ;  *            Copyright 1998-1999 Symantec Corporation                *
  5. ;  *                Created by Larry R. McDowall                           *
  6. ;  *                                                                          *
  7. ;  *******************************************************************
  8. ;
  9. ;
  10. ;
  11. ;
  12. ;    TABLE OF CONTENTS
  13. ;    *****************
  14. ;
  15. ;    Introduction        Describes the purpose of this script.
  16. ;    How This Script Works    Brief description of what this script does.
  17. ;    Setup and Installation    How to install and use this script.
  18. ;    Support            How to obtain support for this script.
  19. ;    Main Body of Script    The script's code and subroutines.
  20. ;    Technical Overview    This appears after the main body of the script.
  21. ;                This section includes extensive descriptions
  22. ;                of how this script works.
  23. ;
  24. ;
  25. ;    INTRODUCTION
  26. ;    ************
  27. ;
  28. ;    The purpose of this script is to illustrate how to use key procedures
  29. ;     in the pcANYWHERE Scripting Language. For more information on these
  30. ;    procedures, please refer to the Technical Overview at the end of this
  31. ;    script.
  32. ;
  33. ;    The following procedures are included in this script:
  34. ;
  35. ;    * How to check for errors and lost connections.
  36. ;    * How to schedule a script.
  37. ;    * How to run a script from a command line.
  38. ;    * How to use a log file.
  39. ;    * How to use a data file to call multiple hosts using a modem.
  40. ;    * How to transfer a file.
  41. ;    * How to run a program.
  42. ;    * How to pause a script while a program runs.
  43. ;
  44. ;
  45. ;    HOW THIS SCRIPT WORKS
  46. ;    *********************
  47. ;
  48. ;    The following describes how this script works:
  49. ;
  50. ;    1. Create or open the log file LOG.TXT, the host data file HOSTS.TXT,
  51. ;       and the sample application SCRIPT.BAT.
  52. ;
  53. ;    2. Read the next host computer's name to call from the DATA.TXT file.
  54. ;
  55. ;    3. Call the next host computer using a modem as read from the DATA.TXT
  56. ;       file.
  57. ;
  58. ;    4. Transfer the remote computer's C:\SCRIPT.BAT file to the host
  59. ;       computer's C: drive.
  60. ;
  61. ;    5. Delete the flag file PCA.FLG on both the remote and host computers
  62. ;       if it exists on either of them.
  63. ;
  64. ;    6. Run the SCRIPT.BAT file on the host computer.
  65. ;
  66. ;    7. Pause the script while the SCRIPT.BAT file runs. The script loops
  67. ;       looking for the existence of the new PCA.FLG file that the SCRIPT.BAT
  68. ;       file will create once it is finished.
  69. ;
  70. ;    8. After the script detects the PCA.FLG file which indicates that the
  71. ;       SCRIPT.BAT file has finished, disconnect from the host computer.
  72. ;
  73. ;    9. If there are more host computers to call, the script goes back to
  74. ;       number 2 and continues until there are no more hosts to call.
  75. ;
  76. ;    10. The script closes the LOG.TXT and DATA.TXT files. If any errors
  77. ;        occurred while the script ran, the LOG.TXT file is displayed using
  78. ;        the Notepad application from Windows.
  79. ;
  80. ;    11. The script ends.
  81. ;    
  82. ;
  83. ;    SETUP AND INSTALLATION
  84. ;    **********************
  85. ;
  86. ;    Step 1. Use a supported version of pcANYWHERE on both the remote and
  87. ;        host computers. Apply any updates for each from the Symantec
  88. ;        web site or BBS. This script supports the following pcANYWHERE
  89. ;        versions running on the specified operating systems:
  90. ;
  91. ;        * pcAnywhere 9.0 for Windows 95/98 and Windows NT 4.0.
  92. ;            * pcANYWHERE 2.0 for Windows 3.1 and Windows 95.
  93. ;            * pcANYWHERE 5.0 for DOS.
  94. ;        * Scripts running between pcAnywhere 9.0 to
  95. ;          pcANYWHERE 5.0 are NOT supported. For more information, please
  96. ;              refer to the Symantec Knowledge Base document "How to Write a
  97. ;          Script from pcANYWHERE32 to a DOS-based pcANYWHERE".
  98. ;        * NOTE: Any version of pcANYWHERE other than those listed above
  99. ;          are not supported. If you experience issues when using an old
  100. ;          version of pcANYWHERE, it is strongly recommended to upgrade
  101. ;          to a current version.
  102. ;    
  103. ;    Step 2. Copy this script to your pcANYWHERE program directory on the
  104. ;        remote computer.
  105. ;
  106. ;    Step 3. There will be one host that will be called twice using a modem,
  107. ;        named "MODEM". This remote control item requires the host
  108. ;        computer's modem number, along with a logon name and password
  109. ;        (if applicable). 
  110. ;
  111. ;        * pcAnywhere 9.0 already have a MODEM item located under the
  112. ;              "Remote Control" area. Enter your host's modem number in
  113. ;              it's Properties section under the Settings tab.
  114. ;        * All other versions of pcANYWHERE will need to have the MODEM
  115. ;          remote control item created and then have the host's modem
  116. ;          number entered into its properties.
  117. ;
  118. ;    Step 4. The host computer must be put into "waiting" mode, waiting for
  119. ;        an incoming call from the remote computer. Ensure that the
  120. ;        modem line used by the host does not have any other device, such
  121. ;        as a fax machine or voice mail, attached to it.
  122. ;
  123. ;    Step 5. Run the script from pcANYWHERE on your remote computer.
  124. ;
  125. ;
  126. ;    SUPPORT
  127. ;    *******
  128. ;
  129. ;    THIS SCRIPT IS PROVIDED AS-IS. pcANYWHERE Technical Support may answer
  130. ;    specific questions about a specific script command, but they CANNOT
  131. ;    assist you in troubleshooting or programming this or other scripts.
  132. ;
  133. ;    Support may or may not be given if you modify this script in any
  134. ;    way, and then have issues using it. (Does the script work without
  135. ;    modifying it?) However, pcANYWHERE Technical Support does offer a Script
  136. ;    Consulting service which can help you troubleshoot or program a script.
  137. ;
  138. ;    Additional information about how to write or troubleshoot a script can
  139. ;    be found in the Symantec Knowledge Base. The following documents are
  140. ;    important resources there:
  141. ;
  142. ;    How to Obtain Support for the pcANYWHERE Scripting Language
  143. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/199795132936
  144. ;
  145. ;       pcANYWHERE Scripting Language Technical Documents
  146. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/19971014101427
  147. ;
  148. ;    How to Write a Script to Connect to a Host Computer
  149. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/19971027103518
  150. ;
  151. ;    How to Write a Script to Connect to an Online Service
  152. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/19971020125713
  153. ;
  154. ;    How to Troubleshoot a Script
  155. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/199791784013
  156. ;    
  157. ;    How to Transfer Files to or From an Online Service Using a Script
  158. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/19978129140
  159. ;
  160. ;       Additionally, pcAnywhere 9.0 has known documented issues when performing
  161. ;    file transfers with the Scripting Language. This unfortunately limits
  162. ;    its effectiveness, as outlined here:
  163. ;
  164. ;    How to Transfer Files to or From a Host Computer Using a Script
  165. ;    http://service1.symantec.com/SUPPORT/pca.nsf/docid/1997625141045
  166. ;
  167. ;    Updates to this script can be found on the Symantec web site, at:
  168. ;
  169. ;    pcANYWHERE Files and Updates
  170. ;    http://www.symantec.com/techsupp/pca/files_pca.html
  171. ;
  172. ;    Script Consulting provides two levels of support for your pcANYWHERE
  173. ;    Scripting Language needs:
  174. ;
  175. ;    1. Script Consulting and Troubleshooting. This is a fee-based service.
  176. ;       This service covers answering advanced questions about how to use
  177. ;       the Scripting Language or how to program it, and also provides
  178. ;       troubleshooting for a script that you have written.
  179. ;
  180. ;    2. Script Programming. This is a fee-based service where a Script
  181. ;       Consultant will program a script for you to your specifications.
  182. ;
  183. ;    If you are interested in obtaining Script Consulting or Programming, you
  184. ;    may contact pcANYWHERE Technical Support and request that a Script
  185. ;    Consultant contact you to discuss your needs. Please contact our
  186. ;    StandardCare support number for this service:
  187. ;
  188. ;    pcANYWHERE StandardCare Support: (541) 465-8430
  189.  
  190.  
  191.  
  192.  
  193. ; *******************************************************************
  194. ; VARIABLES - Declares variables for the script to use.
  195. ; *******************************************************************
  196.  
  197. Integer ERR_COUNT             ; Total number of errors during script.
  198. Integer I                 ; Increments to allow script to pause.
  199. Integer LOOP                 ; Sets total number of loops to use.
  200. Integer RES                 ; Sets success/failure of a subroutine.
  201. String CDIR[255]             ; Sets the working directory.
  202. String CDIR2[255]             ; The secondary string for the work dir.
  203. String ERR[255]                 ; Stores $ERROR value if error occurs.
  204. String ERR_AMOUNT[255]             ; Allows log file to save $ERROR value.
  205. String HOST[255]             ; Name of the host computer to call.
  206. String LOG[255]                 ; The primary log description.
  207. String LOG2[255]             ; The secondary log description.
  208. String SOURCE[255]             ; Source file name to file transfer.
  209. CDIR = $CURDIR                 ; Assign CDIR to the working directory.
  210. StrLen CDIR                 ; Check for root drive.
  211. If $RESULT == 3 Then SubStr CDIR 1 2  CDIR  ; If root, remove "\" in path name.
  212.  
  213.  
  214. ; *******************************************************************
  215. ; MAIN - Controls branching to subroutines.
  216. ; *******************************************************************
  217. ;
  218. ; NOTE 1: If you want the script to schedule itself to begin execution at a
  219. ; later date and time than when you run it, remove the semicolon to the left of
  220. ; the "Wait Until 2359" command found at the beginning of the MAIN
  221. ; subroutine.
  222. ;
  223. ; By default, the script will then begin execution at 11:59 PM on the same day
  224. ; it was run. You may want to change the time to start from 2359 to something a
  225. ; few minutes from when you will be testing the script. Use 24-hour format for
  226. ; the time.
  227. ;
  228. ; A script runs on the same day it is launched with this method. If you assign
  229. ; the time to be 0000, midnight, then the script will not run, but will stay
  230. ; as a black terminal window (its dormant mode until it would have normally
  231. ; started). This is because midnight has already occurred today. Instead, use
  232. ; 2359 or a similar "near-midnight" time for the current day, as in the
  233. ; example above.
  234. ;
  235. ; For more information on how to schedule a script, please refer to the sections
  236. ; "How to Schedule a Script Using a Third Party Scheduler" and "How to Program a
  237. ; Script to Schedule Itself" which are both found in the Technical Overview at
  238. ; the end of the script.
  239. ;
  240. ; NOTE 2: If you do not want the script to display the log file if errors
  241. ; occurred, add a semicolon to the left of the "If ERR_COUNT > 0 THEN GoSub
  242. ; @DISPLAY_LOG" command line near the end of the MAIN subroutine.
  243. ;
  244. ; Please refer to the DISPLAY_LOG subroutine for information on how to configure
  245. ; the display of the log file.
  246. ;
  247.  
  248. @MAIN:                     ; The primary subroutine of the script.
  249. ;  Wait Until 2359             ; Schedules script to start at 11:59 PM.
  250.   GoSub @OPEN_FILES             ; Opens necessary files.
  251.   If RES == 1 GoTo @MAIN_END           ; If cannot open log file, abort script.
  252.   If RES == 2 GoTo @MAIN_CLOSE          ; If cannot open other files, end script.
  253.  
  254. @MAIN_CALL_HOSTS:             ; Main subroutine that controls and calls
  255.                      ; other subroutines.
  256.   RES = 0                 ; Reset subroutine success/failure.
  257.   GoSub @NEXT_HOST             ; Read next host to call from DATA.TXT.
  258.   If RES == 1 GoTo @MAIN_CLOSE          ; If no more hosts to call, end script.
  259.   GoSub @CALL_HOST             ; Call the next host.
  260.   If RES == 1 GoTo @MAIN_CALL_HOSTS  ; If call to host failed, call next host.
  261.   GoSub @TRANSFER_FILE             ; Transfer the SCRIPT.BAT file to host.
  262.   If RES == 1 GoTo @MAIN_DISCONNECT  ; If error, disconnect and call next host.
  263.   If RES == 2 GoTo @MAIN_CALL_HOSTS  ; If lost connection, call next host.
  264.   GoSub @RUN_FILE             ; Run the SCRIPT.BAT on the host.
  265.   If RES == 1 GoTo @MAIN_CALL_HOSTS  ; If lost connection, call next host.
  266.  
  267. @MAIN_DISCONNECT:             ; Subroutine used to disconnect from host.
  268.   LOG = "Disconnecting from host '"  ; Create a log description.
  269.   StrCat LOG HOST             ; Add host's name to the description.
  270.   StrCat LOG "'."             ; End the description.
  271.   GoSub @WRITE_LOG             ; Write the description to the log.
  272.   If $DCD !=1 Then GoSub @LOST_CONNECTION  ; Lost connection.
  273.   If $DCD == 1 Then Session End         ; Disconnect from the host.
  274.   GoTo @MAIN_CALL_HOSTS             ; Call the next host.
  275.  
  276. @MAIN_CLOSE:                 ; Subroutine used to end the script.
  277.   ERR_AMOUNT = ERR_COUNT         ; Convert ERR_COUNT to a string.
  278.   LOG = "Script completed with "     ; Create a log description.
  279.   StrCat LOG ERR_AMOUNT             ; Add total errors that occurred.
  280.   LOG2 = " error(s)."             ; Add " errors(s)." to the description.
  281.   StrCat LOG LOG2             ; End the description.
  282.   GoSub @WRITE_LOG             ; Write the description to the log.
  283.   Close 1                 ; Close the log file.
  284.   Close 2                 ; Close the DATA.TXT file.
  285.  
  286. @MAIN_END:                 ; Subroutine used to end the script.
  287.   If ERR_COUNT > 0 Then GoSub @DISPLAY_LOG  ; If any errors, display log file.
  288.   End                     ; End the script.
  289.  
  290.  
  291.  
  292.  
  293. ; *******************************************************************
  294. ; OPEN FILES - Opens or creates necessary files for script to use.
  295. ; *******************************************************************
  296.  
  297. @OPEN_FILES:                 ; Subroutine used to create log file.
  298.   Find First ".\LOG.TXT"         ; Try to find the LOG.TXT file.
  299.   If $RESULT == 1 GoTo @OPEN_FILES_LOG_DATA_SCRIPT  ; If found, open log file.
  300.   Create 1 ".\LOG.TXT" "W"         ; If not found, create it.
  301.   Write Line 1 "**** pcANYWHERE Script Log File ****"  ; Add title.
  302.   Close 1                 ; Close the log file.
  303.  
  304. @OPEN_FILES_LOG_DATA_SCRIPT:         ; Subroutine used to open necessary files.
  305.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  306.   Open 1 ".\LOG.TXT" "W"         ; Open the log file.
  307.   ERR = $ERROR                 ; Assign ERR the value of $ERROR.
  308.   If $ERROR < 0 GoTo @OPEN_FILES_ERROR_LOG  ; If error, abort the script.
  309.   Seek 1 0 2                 ; Position the pointer to end of file.
  310.   Write Line 1 " "             ; Write a blank line.
  311.   LOG = "Starting script."         ; Create log description.
  312.   GoSub @WRITE_LOG             ; Write the description to the log.
  313.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  314.   Create 2 ".\DATA.TXT" "W"         ; Create the HOSTS.TXT file.
  315.   ERR = $ERROR                 ; Assign ERR the value of $ERROR.
  316.   If $ERROR < 0 GoTo @OPEN_FILES_ERROR_DATA  ; If error, end the script.
  317.   Write Line 2 "MODEM"               ; Write 1st name of host to call.
  318.   Write Line 2 "MODEM"             ; Write 2nd name of host to call.
  319.   Close 2                 ; Close the DATA.TXT file.
  320.   Open 2 ".\DATA.TXT" "R"         ; Open DATA.TXT file for read-only.
  321.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  322.   Create 3 "C:\SCRIPT.BAT" "W"         ; Create the SCRIPT.BAT file.
  323.   ERR = $ERROR                 ; Assign ERR the value of $ERROR.
  324.   If $ERROR < 0 GoTo @OPEN_FILES_ERROR_SCRIPT  ; If error, end the script.
  325.   Write Line 3 "@ECHO OFF"         ; Write "@ECHO OFF" to the file.
  326.   Write Line 3 "C:"             ; Write "C:" to the file.
  327.   Write Line 3 "CD \"             ; Write "CD \" to the file.
  328.   Write Line 3 "DIR /A"             ; Write "DIR /A" to the file.
  329.   Write Line 3 "DIR >PCA.FLG"         ; Write "DIR >PCA.FLG" to the file.
  330.   Close 3                 ; Close the SCRIPT.BAT file.
  331.   RES = 0                 ; Set return code to success.
  332.   Return                 ; Return to the MAIN subroutine.
  333.  
  334. @OPEN_FILES_ERROR_LOG:             ; Subroutine used if cannot open log.
  335.   LOG = "Error "             ; Create a message description.
  336.   StrCat LOG ERR             ; Add $ERROR value.
  337.   StrCat LOG " while accessing the LOG.TXT file."  ; End message.
  338.   Type Line LOG                 ; Display the message.
  339.   Wait 10                 ; Wait 10 seconds.
  340.   RES = 1                 ; Set return code to failure.
  341.   Return                 ; Return to the MAIN subroutine.
  342.  
  343. @OPEN_FILES_ERROR_DATA:             ; Subroutine used if cannot open DATA.TXT.
  344.   LOG2 = "while accessing the DATA.TXT file."  ; Create log description.
  345.   GoSub @ERROR                 ; Add the error number.
  346.   RES = 2                 ; Set return code to failure.
  347.   Return                 ; Return to the MAIN subroutine.
  348.  
  349. @OPEN_FILES_ERROR_SCRIPT:         ; Subroutine used if cannot open
  350.                      ; SCRIPT.BAT.
  351.   LOG2 = "while accessing the SCRIPT.BAT file."  ; Create description.
  352.   GoSub @ERROR                 ; Add the error number.
  353.   RES = 2                 ; Set return code to failure.
  354.   Return                 ; Return to the MAIN subroutine.
  355.  
  356.  
  357.  
  358.  
  359. ; *******************************************************************
  360. ; NEXT HOST - Read the next host computer to call from data file.
  361. ; *******************************************************************
  362.  
  363. @NEXT_HOST:                 ; Subroutine used to read next host
  364.                      ; to call.
  365.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  366.   Read Line 2 HOST             ; Assign HOST to the next host to call.
  367.   If $ERROR < 0 GoTo @NEXT_HOST_DONE ; If error, end the script.
  368.   StrLen HOST                 ; Check if HOST value is valid.
  369.   If $RESULT < 1 GoTo @NEXT_HOST_DONE  ; If error, end the script.
  370.   RES = 0                 ; Set return code to success.
  371.   Return                 ; Return to the MAIN subroutine.
  372.  
  373. @NEXT_HOST_DONE:             ; Subroutine used if no more hosts to call.
  374.   RES = 1                 ; Set return code to failure.
  375.   Return                 ; Return to the MAIN subroutine.
  376.  
  377.  
  378.  
  379.  
  380. ; *******************************************************************
  381. ; CALL HOST - Calls the next host computer.
  382. ; *******************************************************************
  383.  
  384. @CALL_HOST:                 ; Subroutine used to call the next host.
  385.   Session Retry 3             ; Retry calling a host three times.
  386.   Session Delay 1             ; Wait one minute before redialing.
  387.   LOG = "Calling host '"         ; Create a log description.
  388.   StrCat LOG HOST             ; Add the host name.
  389.   StrCat LOG "'."             ; End the description.
  390.   GoSub @WRITE_LOG             ; Write the description to the log.
  391.   Wait 5                 ; Used to wait five seconds before dialing
  392.                      ; the host to enable it to correctly reset
  393.                      ; its modem.
  394.   Session Dial HOST             ; Call the host computer.
  395.   If $DCD != 1 GoTo @CALL_HOST_NO_CONNECTION  ; If no connection, call
  396.                                               ; next host.
  397.   LOG = "Successfully connected to host '"  ; Create a log description.
  398.   StrCat LOG HOST             ; Add the host name to the description.
  399.   StrCat LOG "'."             ; End the description.
  400.   GoSub @WRITE_LOG             ; Write the description to the log.
  401.   RES = 0                 ; Set return code to success.
  402.   Return                 ; Return to the MAIN subroutine.
  403.  
  404. @CALL_HOST_NO_CONNECTION:            ; Subroutine used for no connection.
  405.   ERR_COUNT = ERR_COUNT + 1          ; Increment how many errors occurred.
  406.   LOG = "Error: unable to connect to host '"  ; Create a log description.
  407.   StrCat LOG HOST             ; Add the host name.
  408.   StrCat LOG "'."             ; End the description.
  409.   GoSub @WRITE_LOG             ; Write description to the log.
  410.   RES = 1                 ; Set return code to failure.
  411.   Return                 ; Return to the MAIN subroutine.
  412.  
  413.  
  414.  
  415.  
  416. ; *******************************************************************
  417. ; TRANSFER FILE - Transfers a file from the remote to the host.
  418. ; *******************************************************************
  419.  
  420. @TRANSFER_FILE:                 ; Subroutine used to transfer a file.
  421.   SOURCE = "C:\SCRIPT.BAT"           ; Assign the source name.
  422.   If $DCD != 1 GoTo @TRANSFER_FILE_LOST  ; If lost connection, call next host.
  423.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  424.  
  425.   SessOpr Remote Send SOURCE "C:\"   ; Transfer file.
  426. ; This line is for pcAnywhere 9.0 only. For pcANYWHERE 2.0 or 5.0, change
  427. ; the destination name to be "C:\SCRIPT.BAT", not "C:\"
  428.  
  429.   ERR = $ERROR                 ; Assign ERR the value of $ERROR.
  430.   If $ERROR < 0 GoTo @TRANSFER_FILE_ERROR  ; If error, call next host.
  431.   LOG = "Transfer of '"             ; Create a log description.
  432.   StrCat LOG SOURCE             ; Add the source file name.
  433.   LOG2 = "' was successful."         ; Add "' was successful." to description.
  434.   StrCat LOG LOG2             ; End the description.
  435.   GoSub @WRITE_LOG             ; Write the description to the log.
  436.   RES = 0                 ; Set return code to success.
  437.   GoSub @LOOP                 ; Allows time for file manager to reset. 
  438.                      ; Needed for pcAnywhere 9.0 only.
  439.   Return                 ; Return to the MAIN subroutine.
  440.  
  441. @TRANSFER_FILE_ERROR:             ; Subroutine used if file transfer failed.
  442.   LOG2 = "while transferring '"         ; Create a log description.
  443.   StrCat LOG2 SOURCE             ; Add the source file name.
  444.   StrCat LOG2 "'."             ; End the description.
  445.   GoSub @ERROR                 ; Add the error number.
  446.   RES = 1                 ; Set return code to failure.
  447.   Return                 ; Return to the MAIN subroutine.
  448.  
  449. @TRANSFER_FILE_LOST:             ; Subroutine used if lost connection.
  450.   GoSub @LOST_CONNECTION         ; Create and save a log description.
  451.   RES = 2                 ; Set return code to failure.
  452.   Return                 ; Return to the MAIN subroutine.
  453.  
  454.  
  455.  
  456.  
  457. ; *******************************************************************
  458. ; RUN FILE - Runs a file on the host computer.
  459. ; *******************************************************************
  460.  
  461. @RUN_FILE:                 ; Subroutine used to run a file on host.
  462.   Del "C:\PCA.FLG"             ; Delete flag file on remote.
  463.   If $DCD != 1 GoTo @RUN_FILE_LOST   ; If lost connection, call next host.
  464.   SessOpr Host Run "COMMAND.COM /C DEL C:\PCA.FLG"  ; Delete on host.
  465.   GoSub @LOOP                 ; Pause script for five seconds.
  466.   LOG = "Executing 'C:\SCRIPT.BAT' on the host..."  ; Create description.
  467.   GoSub @WRITE_LOG             ; Write the description to the log.
  468.   If $DCD != 1 GoTo @RUN_FILE_LOST   ; If lost connection, call next host.
  469.   SessOpr Host Run "COMMAND.COM /C C:\SCRIPT.BAT"  ; Run SCRIPT.BAT.
  470.   GoSub @LOOP                 ; This is used for pcAnywhere 9.0.
  471.   GoSub @LOOP                 ; Wait another 5 seconds.
  472.   GoSub @LOOP                     ; Wait another 5 seconds.
  473.   GoSub @LOOP                     ; Wait another 5 seconds (total of 20).
  474.  
  475. ; If the above multiple looping fails, an "Invalid Script File" error will
  476. ; occur if pcAnywhere 9.0 is used, since the intended file to tranfer
  477. ; apparently does not yet exist. If so, try adding more "GoSub @LOOP" lines
  478. ; until this error no longer occurs.
  479.  
  480. ;  GoSub @CHECK_FLAG             ; Pause script while SCRIPT.BAT runs.
  481.                      ; Use this line only for pcANYWHERE 2.0
  482.                      ; or 5.0, not for pcAnywhere 9.0.            
  483.   RES = 0                 ; Set return code to success.
  484.   Return                 ; Return to MAIN subroutine.
  485.  
  486. @RUN_FILE_LOST:                 ; Subroutine used if lost connection.
  487.   GoSub @LOST_CONNECTION         ; Create and save a log description.
  488.   RES = 1                 ; Set return code to failure.
  489.   Return                 ; Return to the MAIN subroutine.
  490.  
  491.     
  492.  
  493.  
  494. ; *******************************************************************
  495. ; WRITE LOG - Writes a description to the log file.
  496. ; *******************************************************************
  497.     
  498. @WRITE_LOG:                 ; Subroutine used to write log description.
  499.   Write String 1 $DATE             ; Write the current date.
  500.   Write String 1 " "             ; Write a blank space.
  501.   Write String 1 $TIME             ; Write the current time.
  502.   Write String 1 "   "             ; Write a tab.
  503.   Write Line 1 LOG             ; Write the log description.
  504.   Return                 ; Return to the calling subroutine.
  505.  
  506.  
  507.  
  508.  
  509. ; *******************************************************************
  510. ; DISPLAY LOG - Displays the log file if any errors occurred.
  511. ; *******************************************************************
  512. ;
  513. ; NOTE: If you do not want the script to display the log file if errors
  514. ; occurred, add a semicolon to the left of the "If ERR_COUNT > 0 Then GoSub
  515. ; @DISPLAY_LOG" command line near the end of the MAIN subroutine.
  516. ;
  517. ; Information in the log file is added at the end of it each time the script
  518. ; runs. To view the last script session, you will need to go to the bottom of
  519. ; the log file after Notepad displays it. Use the Ctrl+End keystrokes or use the
  520. ; PageDown key to cycle down to the end.
  521. ;
  522. ; By default, Notepad will be used to display the log file. If the log file
  523. ; becomes too large, you will need to use an alternate text editor such as Write
  524. ; or WordPad. If your remote computer's operating system is DOS, you will need
  525. ; to use a DOS-based text editor such as the EDIT command. You may also need to
  526. ; specify the full path to the EDIT command instead of just it's file name.
  527.  
  528. @DISPLAY_LOG:                 ; Subroutine used to show log file.
  529.   CDIR2 = "NOTEPAD "                 ; Create beginning of the command.
  530.   StrCat CDIR2 CDIR             ; Add the current working directory.
  531.   StrCat CDIR2 "\LOG.TXT"         ; Add the log file name and end.
  532.   RUN CDIR2                 ; Display log file.
  533.   Return                 ; Return to the MAIN subroutine.
  534.  
  535.  
  536.  
  537.  
  538. ; *******************************************************************
  539. ; CHECK FLAG - Loops to pause the script until SCRIPT.BAT finishes.
  540. ; *******************************************************************
  541. ;
  542. ; NOTE 1: If you want to run a program on the remote computer and the script
  543. ; needs to pause while this program runs, the below procedure will need to be
  544. ; changed slightly. The command "SessOpr Host Send "C:\PCA.FLG" "C:\PCA.FLG""
  545. ; will need to be replaced with the commands:
  546. ;
  547. ;    Find First "C:\PCA.FLG"
  548. ;    If $RESULT == 0 GoTo @CHECK_FLAG_FILE
  549. ;
  550. ; This loops the subroutine if the C:\PCA.FLG file cannot be found on the remote
  551. ; computer.
  552. ; Note that this subroutine is not actually used by this script any longer. 
  553. ; pcAnywhere 9.0 will cause an error "Invalid Script File" if this subroutine
  554. ; is used. This is because if the intended file to be transferred does not
  555. ; exist, and issue in version 9.0 will cause this error, thereby hanging the
  556. ; script. The work around is to use the Loop subroutine instead, creating
  557. ; a set delay, and assuming that when it finishes, the intended file to
  558. ; be transferred then exists. More information about this issue can be found
  559. ; here:
  560. ;
  561. ; Error: "Invalid Script File" when Script Runs
  562. ; http://service1.symantec.com/SUPPORT/pca.nsf/docid/199812362852
  563. ;
  564. ; Only pcANYWHERE 2.0 or 5.0 should use this subroutine, if the LOOP subroutine
  565. ; cannot be used in its place.
  566.  
  567.  
  568. @CHECK_FLAG:                 ; Subroutine used to pause the script.
  569.   LOOP = 0                 ; Reset the value of LOOP to 0.
  570.  
  571. @CHECK_FLAG_FILE:             ; Subroutine used find flag file.
  572.   GoSub @LOOP                 ; Pause script for five seconds.
  573.   LOOP = LOOP + 1             ; Increment the value of LOOP.
  574.   If LOOP == 24 GoTo @CHECK_FLAG_ERROR  ; If LOOP takes too long, abort.
  575.   If $DCD != 1 GoTo @CHECK_FLAG_LOST ; If lost connection, end loop.
  576.   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  577.   SessOpr Host Send "C:\PCA.FLG" "C:\PCA.FLG"  ; Attempt file transfer.
  578.   If $ERROR == -8 GoTo @CHECK_FLAG_FILE  ; If file not found, loop.
  579.   If $ERROR < 0 GoTo @CHECK_FLAG_OTHER  ; If other error, end loop.
  580.   LOG = "Execution of 'C:\SCRIPT.BAT' on the host was successful."
  581.                      ; Create a log description.
  582.   GoSub @WRITE_LOG             ; Write the description to the log.
  583.   Del "C:\PCA.FLG"             ; Delete the flag file on the remote.
  584.   If $DCD != 1 GoTo @CHECK_FLAG_LOST ; If lost connection, call next host.
  585.   SessOpr Host Run "COMMAND.COM /C DEL PCA.FLG"    ; Delete on the host.
  586.   RES = 0                 ; Set return code to neutral value.
  587.   Return                  ; Return to the RUN_FILE subroutine.
  588.  
  589. @CHECK_FLAG_ERROR:             ; Subroutine used to time loop out.
  590.   ERR_COUNT = ERR_COUNT + 1          ; Increment how many errors occurred.
  591.   LOG = "Error: execution of 'C:\SCRIPT.BAT' on the host timed out."
  592.                      ; Create a log description.
  593.   GoSub @WRITE_LOG             ; Write the description to the log.
  594.   RES = 0                 ; Set return code to neutral value.
  595.   Return                 ; Return to the RUN_FILE subroutine.
  596.  
  597. @CHECK_FLAG_LOST:             ; Subroutine used if lost connection.
  598.   GoSub @LOST_CONNECTION         ; Create and save a log description.
  599.   RES = 1                 ; Set return code for failure.
  600.   Return                 ; Return to the RUN_FILE subroutine.
  601.  
  602. @CHECK_FLAG_OTHER:             ; Subroutine used for generic error.
  603.   LOG2 = "occurred while running 'C:\SCRIPT.BAT' on the host."
  604.                      ; Create a log description.
  605.   GoSub @ERROR                 ; Add the error number.
  606.   RES = 0                 ; Set return code to neutral value.
  607.   Return                 ; Return to the RUN_FILE subroutine.
  608.  
  609.  
  610.  
  611.  
  612. ; *******************************************************************
  613. ; LOOP - Pauses script by incrementing an integer.
  614. ; *******************************************************************
  615. ;
  616. ; NOTE: By default, the LOOP subroutine pauses the script for about five
  617. ; seconds. This time is determined by the number 50,000. You may need to
  618. ; increase or decrease this number depending on the speed of your remote
  619. ; computer however.
  620. ;
  621. ; This subroutine is now used to pause the script, instead of the CHECK_FLAG
  622. ; subroutine. Please refer to that subroutine for information on this.
  623.  
  624. @LOOP:                     ; Subroutine used to pause the script.
  625.   I = 0                     ; Reset the value of I to 0.
  626.  
  627. @LOOP_SCRIPT:                 ; Subroutine used loop the script.
  628.   I = I + 1                 ; Increment the value of I.
  629.   If I != 50000 GoTo @LOOP_SCRIPT    ; If not five seconds, loop.
  630.   Return                 ; Return to calling subroutine.
  631.  
  632.  
  633.  
  634.  
  635. ; *******************************************************************
  636. ; ERROR - Writes error number to the log file.
  637. ; *******************************************************************
  638.  
  639. @ERROR:                     ; Subroutine used to trap errors.
  640.   ERR_COUNT = ERR_COUNT + 1          ; Increment how many errors occurred.
  641.   LOG = "Error "             ; Create a log description.
  642.   StrCat LOG ERR             ; Add the error number.
  643.   StrCat LOG " occurred "         ; Add " occurred ".
  644.   StrCat LOG LOG2             ; Add the description.
  645.   GoSub @WRITE_LOG             ; Write the description to the log.
  646.   Return                 ; Return to the calling subroutine.
  647.  
  648.  
  649.  
  650.  
  651. ; *******************************************************************
  652. ; LOST CONNECTION - Write lost connection information to log file.
  653. ; *******************************************************************
  654.  
  655. @LOST_CONNECTION:             ; Subroutine used to trap lost connections.
  656.   ERR_COUNT = ERR_COUNT + 1          ; Increment how many errors occurred.
  657.   LOG = "Error: lost connection to host '"  ; Create description.
  658.   StrCat LOG HOST             ; Add the host name.
  659.   StrCat LOG "'."             ; End the description.
  660.   GoSub @WRITE_LOG             ; Write the description to the log.
  661.   Return                 ; Return to the calling subroutine.
  662.  
  663.  
  664.  
  665.  
  666. ;    **************************
  667. ;    **  TECHNICAL OVERVIEW  **
  668. ;    **************************
  669. ;
  670. ;    
  671. ;
  672. ;
  673. ;    TABLE OF CONTENTS FOR TECHNICAL OVERVIEW
  674. ;    ****************************************
  675. ;
  676. ;    Subroutines
  677. ;    How to Troubleshoot this Script
  678. ;    Checking a Command's Results After it Runs - How to Use $RESULT
  679. ;    Checking for Errors When a Script Runs - How to Use $ERROR
  680. ;    Checking for Lost Connections - How to Use $DCD
  681. ;    How to Use a Network or Cable to Connect to a Host Using a Script
  682. ;    How to Convert an Integer to a String Variable
  683. ;    How to Schedule a Script Using a Third Party Scheduler
  684. ;    How to Program a Script to Schedule Itself
  685. ;    How to Run a Script From a Command Line
  686. ;    How to Create and Use a Log File
  687. ;    How to Use a Data File to Call Multiple Host Computers
  688. ;    How to Call a Host Computer
  689. ;    How to Transfer Files
  690. ;    How to Run a Program
  691. ;    How to Pause a Script While a Program Runs
  692. ;    Using "Infinite" Loops
  693. ;
  694. ;
  695. ;    SUBROUTINES
  696. ;    ***********
  697. ;
  698. ;    The following briefly describes the subroutines that are found in this
  699. ;    script:
  700. ;
  701. ;    SUBROUTINE NAME        PURPOSE
  702. ;    ----------------------------------------------------------------------
  703. ;    VARIABLES        Defines variables that will be used.
  704. ;
  705. ;    MAIN                The primary subroutine of the script which
  706. ;                controls other subroutines.
  707. ;
  708. ;    OPEN_FILES        Creates or opens the log file LOG.TXT, the host
  709. ;                data file DATA.TXT, and the sample application
  710. ;                SCRIPT.BAT.
  711. ;
  712. ;    NEXT_HOST          Reads the next host computer to call by reading
  713. ;                the DATA.TXT text file.
  714. ;
  715. ;    CALL_HOST          Calls the next host computer.
  716. ;
  717. ;    TRANSFER_FILE          Transfers the C:\SCRIPT.BAT file from the remote
  718. ;                computer to the host computer's C:\ drive.
  719. ;
  720. ;    RUN_FILE          Runs the SCRIPT.BAT file on the host computer
  721. ;                and branches to the CHECK_FLAG subroutine to
  722. ;                pause the script while it runs.
  723. ;
  724. ;    WRITE_LOG          Writes a text description defined by the calling
  725. ;                subroutine to the log file.
  726. ;
  727. ;    DISPLAY_LOG        If any errors occurred while the script ran,
  728. ;                     displays the log file after the script has
  729. ;                  finished.
  730. ;
  731. ;    CHECK_FLAG          Pauses the script while looking for the flag
  732. ;                file PCA.FLG on the host computer. This file is
  733. ;                created when the SCRIPT.BAT file finishes. When
  734. ;                this file is detected by the script, the script
  735. ;                then continues where it left off. This 
  736. ;                subroutine is no longer used, in lieu of the
  737. ;                LOOP subroutine.
  738. ;
  739. ;    LOOP            Pauses the script by looping an integer. This
  740. ;                pauses the script for approximately five
  741. ;                seconds.
  742. ;
  743. ;    ERROR              Writes the error number to the log file.
  744. ;
  745. ;    LOST_CONNECTION          Writes information about the lost connection to
  746. ;                the log file.
  747. ;
  748. ;
  749. ;    HOW TO TROUBLESHOOT THIS SCRIPT
  750. ;    *******************************
  751. ;
  752. ;    This script has been extensively tested before being released for
  753. ;    public use. However, other factors could cause issues that would
  754. ;    prevent this script from working correctly. Please check the following
  755. ;    list to ensure that these are correct on your systems:
  756. ;
  757. ;    1. Have you modified the script in any way? Often people will change
  758. ;       something in the script which would then cause it to not work
  759. ;       correctly. This particularly pertains to the file names that the
  760. ;       script uses, such as the LOG.TXT or the SCRIPT.BAT. Do you experience
  761. ;       the same issue if you run the original SAMPLE.SCRAW file? If not, then
  762. ;       the issue is in your modified version of the script. If so, then you
  763. ;       are most likely experiencing some other type of issue.
  764. ;
  765. ;    2. Did you create the "MODEM" remote control item in the Remote Control
  766. ;       section of your pcANYWHERE remote computer? This item is required by
  767. ;       the script before it is able to dial your host computer correctly.
  768. ;       This process is explained under SETUP AND INSTALLATION at the
  769. ;       beginning of this script.
  770. ;
  771. ;    3. Did you install the script to the pcANYWHERE program directory? This
  772. ;       script may not work correctly if installed to an alternate directory.
  773. ;       This process is explained under SETUP AND INSTALLATION at the
  774. ;       beginning of this script.
  775. ;
  776. ;    4. Do issues exist between the remote and host computers? Is the speed
  777. ;       of the connection slow when connecting manually? Do you receive error
  778. ;       messages or lost connections when connecting manually? If so, you
  779. ;         will need to resolve these issues before continuing trying to use
  780. ;       a script to connect them together.
  781. ;
  782. ;
  783. ;    CHECKING A COMMAND'S RESULTS AFTER IT RUNS - HOW TO USE $RESULT
  784. ;    ***************************************************************
  785. ;
  786. ;    The global variable $RESULT stores the result value of the last script
  787. ;    command to run. $RESULT cannot be manually set by the script, such as
  788. ;    in "$RESULT = 0", but is only set after a command finishes executing.
  789. ;    The value of $RESULT will differ depending on which script command sets
  790. ;    it. For more information on what each script command will set the value
  791. ;    of $RESULT to, please refer to the appropriate script command in the
  792. ;    Creating Scripts book.
  793. ;
  794. ;    Because $RESULT is set by almost every script command, it is
  795. ;    recommended to store the value of $RESULT in a user-defined variable
  796. ;    before trying to check it or return a value from a GoSub...Return loop.
  797. ;    For example, if you need to check $RESULT by using two consecutive
  798. ;    If...Then commands, the first If...Then command will actually set the
  799. ;    value of $RESULT itself, giving the second If...Then command an
  800. ;    incorrect value because it was checking the previous command.
  801. ;
  802. ;    This script uses the user defined variable RES to save the success or
  803. ;    failure status of called subroutines from the MAIN subroutine. The
  804. ;    status could have been passed back to it from the Return command,
  805. ;    however as mentioned above, consecutive If...Then statements will change
  806. ;    the value of $RESULT. Because of this, the status from a called
  807. ;    subroutine is saved to RES, which allows the script to control exactly
  808. ;    what values are saved and checked for. For example:
  809. ;
  810. ;        SessOpr Remote Send "C:\DATA\*.DBF" "C:\NEW\"
  811. ;        RES = $RESULT
  812. ;        If RES <= 4 GoSub @ERROR
  813. ;        If RES > 4 Then @OK
  814. ;    
  815. ;    Please note that the above example is not meant to be run by itself, but
  816. ;    has been provided here as an example on how to set and check $RESULT.
  817. ;    The first line transfers all *.DBF files from the remote's C:\DATA\
  818. ;    directory to the host's C:\NEW\ directory. The second line assigns the
  819. ;    value of $RESULT to the variable RES. The third line checks to see if at
  820. ;    least five of the *.DBF files were sent successfully (four or less); if
  821. ;    not, then the script will branch off to the ERROR subroutine.  The last
  822. ;    line double checks to see if four or more files were sent, if so then
  823. ;    the script goes to the OK subroutine.
  824. ;
  825. ;
  826. ;    CHECKING FOR ERRORS WHEN A SCRIPT RUNS - HOW TO USE $ERROR
  827. ;    **********************************************************
  828. ;
  829. ;    The global variable $ERROR is similar to the $RESULT global variable,
  830. ;    however it is set to the error condition of the last script command to
  831. ;    run, whereas $RESULT is set to the result value of the last script
  832. ;    command to run. If the value of $ERROR is a negative number, then the
  833. ;    script encountered an error. If it is zero, then no errors occurred.
  834. ;    It is important to check $ERROR to ensure that script commands worked
  835. ;    correctly.
  836. ;
  837. ;    Unlike $RESULT which is only set by the last script command, the value
  838. ;    of $ERROR can be set manually by the script. It is recommended to set
  839. ;    $ERROR to zero before running a command and checking it's value. If this
  840. ;    is not done, then $ERROR will retain the last error value that set it;
  841. ;    if a command runs and no errors occur, this does not reset $ERROR to
  842. ;    zero. After the script command runs, check to see if $ERROR is less than
  843. ;    zero; if so, than an error occurred. For example:
  844. ;    
  845. ;        $ERROR = 0
  846. ;        SessOpr Remote Send "C:\AUTOEXEC.BAT" "C:\NEW.BAT"
  847. ;        If $ERROR < 0 GoSub @ERROR
  848. ;
  849. ;    Please note that the above example is not meant to be run by itself,
  850. ;    but has been provided here as an example on how to set and check $ERROR.
  851. ;    The first line resets the value of $ERROR to zero. The second line
  852. ;    transfers the AUTOEXEC.BAT file to the host's new file NEW.BAT. The
  853. ;    third line checks to see if any error occurred; if so, then the script
  854. ;    will branch off to the ERROR subroutine.
  855. ;
  856. ;    This script frequently checks $ERROR. If an error occurs, either a local
  857. ;    subroutine is called, or the ERROR subroutine is called. These
  858. ;    subroutines write the status of the error to the log file then continue
  859. ;    where the script left off.
  860. ;
  861. ;
  862. ;    CHECKING FOR LOST CONNECTIONS - HOW TO USE $DCD
  863. ;    ***********************************************
  864. ;
  865. ;    The global variable $DCD (Data Carrier Detect) is used to check the
  866. ;    status of the connection between the remote and host computers when
  867. ;    modems are used. If you want to connect using a network or direct
  868. ;    connection cable, please refer to the next section called "How to
  869. ;    Use a Network or Cable to Connect to a Host Using a Script". It is
  870. ;    important to check $DCD to ensure that a valid connection exists.
  871. ;    
  872. ;    If the value of $DCD is a one, then the computers are connected. If
  873. ;    it is not equal to one (not necessarily zero), then the computers did
  874. ;    not connect or the connection was dropped (lost connection) while in
  875. ;    a session. Like $RESULT, $DCD cannot be set manually by the script but
  876. ;    is set according to the connection status of the modems.
  877. ;
  878. ;    Important Note for Lost Connections: The value of $DCD is used to check
  879. ;    to see if the remote computer is still connected to the host computer by
  880. ;    modems. However, the value of $DCD may be unreliable because if a lost
  881. ;    connection occurs, the remote computer's modem may take a few moments to
  882. ;    detect and report this. If this is the case, the pcANYWHERE Scripting
  883. ;    Language will be unable to detect the lost connection as well. Different
  884. ;    timing issues on the remote computer that could play a part in this
  885. ;    delay are: the type of modem it uses, the TAPI driver used or it's
  886. ;    initialization string, the speed of the remote computer, and the phone
  887. ;    lines involved. Because of these facts, you may or may not encounter
  888. ;    issues while checking for a lost connection, depending on how the lost
  889. ;    connection occurred. For example, if you drop the connection on the host
  890. ;    computer by unplugging it's phone line, the remote computer will usually
  891. ;    not be able to detect this immediately. However, a lost connection
  892. ;    which occurred due to phone line noise, i.e., a real lost connection not
  893. ;    a simulated one, should be usually detected and accounted for.
  894. ;
  895. ;    It is important to check the value of $DCD before running the following
  896. ;    commands: SessOpr Remote Send and SessOpr Host Send, SessOpr Remote Run
  897. ;    and SessOpr Host Run, and Session End. Also, $DCD should be checked
  898. ;    after a Session Dial command to ensure that a connection was established
  899. ;    correctly. These five commands can only be run from a session started by
  900. ;    the Session Dial command. If they are used and a session is not active,
  901. ;    then several issues may occur, such as: an "AWREM32" error message, a
  902. ;    "Fatal Exception" error message, an "Invalid Script File" error message,
  903. ;    the script hangs, a black Terminal window appears, or script error
  904. ;    messages -23 or -26 appear. Therefore, the value of $DCD needs to be a 1
  905. ;    before running one of these commands; $DCD should be used to check this
  906. ;    before running them. The following is an example on how to check the
  907. ;    value of $DCD before running one of these commands:
  908. ;
  909. ;        If $DCD != 1 GoTo @LOST_CONNECTION
  910. ;        SessOpr Host Send "C:\NEW\*.DOC" "C:\DOCS\"
  911. ;
  912. ;    Please note that the above example is not meant to be run by itself, but
  913. ;    has been provided here as an example on how to set and check $DCD. Also,
  914. ;    $ERROR checking was left out; normally the script should set $ERROR to
  915. ;    zero before running the command, and then check it's value after the
  916. ;    command finishes running. (As outlined in the prior example for $ERROR.)
  917. ;    The first line checks $DCD to see if it is not equal to one; if it is
  918. ;    not, then a lost connection occurred and the script will then branch off
  919. ;    to the LOST_CONNECTION subroutine. The second line transfers the all
  920. ;    *.DOC files in the host computer's C:\NEW\ directory to the remote
  921. ;    computer's C:\DOCS\ directory.
  922. ;
  923. ;    This script frequently checks $DCD. If a lost connection is found,
  924. ;    either a local subroutine is called, or the LOST_CONNECTION subroutine
  925. ;    is called. These subroutines write the status of the lost connection
  926. ;    to the log file then continue where the script left off.
  927. ;
  928. ;
  929. ;    HOW TO USE A NETWORK OR CABLE TO CONNECT TO A HOST USING A SCRIPT
  930. ;    *****************************************************************
  931. ;
  932. ;    The global variable $DCD (Data Carrier Detect) is used to check for the
  933. ;    connection status of modem connections. However, since there is no
  934. ;    $DCD value for a network or cable connection, this variable cannot be
  935. ;    used to check for these types of connections.
  936. ;
  937. ;    If you want to use this sample script to connect to a network or cable
  938. ;    host, then you will need to remove any line that checks for the value
  939. ;    of $DCD. Since $DCD will equal a 0, indicating that no modem connection
  940. ;    is present, even though the remote connected correctly to a network or
  941. ;    cable host, it will immediately detect it as a lost connection and
  942. ;    act accordingly as programmed into this script.
  943. ;
  944. ;    There is no good way to detect whether or not a remote is connected to
  945. ;    a network or direct connect host, however. A direct connect host has
  946. ;    no method to determine if it is connected, other than trying to transfer
  947. ;    a test file to it to see if the connection is valid. This may cause the
  948. ;    script or remote to hang, since the SessOpr Remote Send command should
  949. ;    only be used in a valid remote control session. Therefore, this is not
  950. ;    a good work around, but is the only one that is known.
  951. ;
  952. ;    For a network connection, a better work around is to have the script run
  953. ;    a batch file to copy a file to a network drive, and then use the IF EXIST
  954. ;    batch file command to see if the file was successfully sent. If so, the
  955. ;    batch file could create a dummy flag file that the script waits to find.
  956. ;    If the script finds this file, then it can assume that the network
  957. ;    connection has been successful and then continue the script.
  958. ;
  959. ;
  960. ;    HOW TO CONVERT AN INTEGER TO A STRING VARIABLE
  961. ;    **********************************************
  962. ;
  963. ;    Variable conversion is a straightforward process in the pcANYWHERE
  964. ;    Scripting Language. Just assign the string variable to the integer
  965. ;    variable, and the conversion is complete.
  966. ;
  967. ;    It may be more difficult to convert a string to an integer however.
  968. ;    The string cannot contain any letters or special characters, otherwise
  969. ;    the conversion cannot take place. The following are some examples of
  970. ;    performing both types of conversions:
  971. ;
  972. ;        String X[5]
  973. ;        Integer Y
  974. ;        Y = 5
  975. ;        X = Y        ; Converts Y's value of decimal 5 to string "5"        
  976. ;        X = "6"
  977. ;        Y = X         ; Converts X's value of string "6" to decimal 6    
  978. ;
  979. ;
  980. ;    HOW TO SCHEDULE A SCRIPT USING A THIRD PARTY SCHEDULER
  981. ;    ******************************************************
  982. ;
  983. ;    The recommended method to schedule a script to run at a later date
  984. ;    and time is to use a third party scheduler, such as the one
  985. ;    supplied with Norton AntiVirus. The scheduler would run the script by
  986. ;    using the pcANYWHERE command line syntax. Please refer to the section
  987. ;    "How to Run a Script from a Command Line" for more information.
  988. ;
  989. ;
  990. ;    HOW TO PROGRAM A SCRIPT TO SCHEDULE ITSELF
  991. ;    ******************************************
  992. ;
  993. ;    If you do not have a third party scheduler, then you can use either the
  994. ;    Wait Until or Session Dial commands to "schedule" your script for you.
  995. ;    Both of these commands can use optional date and time parameters to
  996. ;    suspend script operations until the date and time that you specify. For
  997. ;    example:
  998. ;
  999. ;        Wait Until 2359 19991221
  1000. ;
  1001. ;    The Wait Until command will pause the script from continuing until
  1002. ;    11:59 PM on December 21st, 1999. (This will only work if the remote
  1003. ;    pcANYWHERE is pcAnywhere 9.0. All other versions only use the last
  1004. ;    two digits of the year instead of four digits.) Both the Wait Until and
  1005. ;    Session Dial commands use a 24-hour time format, so 11:59 PM becomes
  1006. ;    2359.
  1007. ;
  1008. ;    You can run the script any time before the target time, such as when you
  1009. ;    go home from work for the day. The script will respond with a black
  1010. ;    terminal window, which is what the script looks like while it is
  1011. ;    waiting to begin execution. (This window can be minimized if the
  1012. ;    remote computer is running Windows so that you can continue working on
  1013. ;    the remote computer.) Once the time is reached, the script then begins
  1014. ;    it's normal execution.
  1015. ;
  1016. ;    A disabled Wait Until command is available for you to use at the
  1017. ;    beginning of the MAIN subroutine.
  1018. ;
  1019. ;    Additional information about using the Wait Until command can be found
  1020. ;    in the NOTE 1 section of the MAIN subroutine.
  1021. ;
  1022. ;
  1023. ;    HOW TO RUN A SCRIPT FROM A COMMAND LINE
  1024. ;    ***************************************
  1025. ;
  1026. ;    Each version of pcANYWHERE requires a different command line:
  1027. ;
  1028. ;    pcAnywhere 9.0: AWREM32.EXE <script name>.SCRAW
  1029. ;    C:\PROGRAM FILES\SYMANTEC\PCANYWHERE\AWREM32.EXE C:\SCRIPTS\SAMPLE.SCRAW
  1030. ;
  1031. ;    pcANYWHERE 2.0:    WINAW.EXE -O=R -M=S -N=<script name>.SCRAW
  1032. ;    C:\WINAW\WINAW.EXE -O:R -M:S -N:C:\SCRIPTS\SAMPLE.SCRAW
  1033. ;
  1034. ;    pcANYWHERE 5.0:    AW.EXE /O:S /M:S /N:<script name>.SCRAW
  1035. ;    C:\AW\AW.EXE /O:S /M:S /N:C:\SCRIPTS\SAMPLE.SCRAW
  1036. ;
  1037. ;    Please note that the above examples must include full path names to the
  1038. ;    executable file and the script file. Also, if the path name is longer
  1039. ;    than eight characters or has spaces, you may need to enclose the path
  1040. ;    name in quotation marks:
  1041. ;
  1042. ;    "C:\PROGRAM FILES\SYMANTEC\PCANYWHERE\AWREM32.EXE" C:\SCRIPTS\SAMPLE.SCRAW
  1043. ;
  1044. ;    
  1045. ;    HOW TO CREATE AND USE A LOG FILE
  1046. ;    ********************************
  1047. ;
  1048. ;    A log file can be created that will record the success or failure of
  1049. ;    specific procedures when the script runs. The values of $ERROR or $DCD
  1050. ;    can be checked by other subroutines in the script, and when an error
  1051. ;    occurs, logged into the log file.
  1052. ;
  1053. ;    This script creates a log file called LOG.TXT. Each entry in the log
  1054. ;    file includes the date and time that they were made, which is performed
  1055. ;    by the WRITE_LOG subroutine.
  1056. ;
  1057. ;    The log file is stored in the pcANYWHERE program directory. To view this
  1058. ;    log file, use any text editor or word processor. The last script session
  1059. ;    to run is added to the bottom of the log file information.
  1060. ;    
  1061. ;    Please refer to the OPEN_FILES and WRITE_LOG subroutines to learn how to
  1062. ;    create and write to a log file respectively.
  1063. ;
  1064. ;    Please note that a log file's scope is to save success or failure
  1065. ;    information on procedures that the script performs. Events that occur
  1066. ;    outside of the pcANYWHERE Scripting Language, such as the remote
  1067. ;    computer hanging while a script runs, it beyond the script's ability to
  1068. ;    detect and account for.
  1069. ;
  1070. ;    Troubleshooting note: if the script hangs or is terminated while it is
  1071. ;    running, the log file may remain open and you may not be able to run the
  1072. ;    script again without getting an error, or be able to view the log file.
  1073. ;    If so, close pcANYWHERE and then load pcANYWHERE again. If you still
  1074. ;    cannot run the script or view the log file, you will need to reboot the
  1075. ;    remote computer.
  1076. ;
  1077. ;    The following is an example of a log file generated by this script:
  1078. ;
  1079. ; **** pcANYWHERE Script Log File ****
  1080. ; 12/22/97 13:47:45   Starting script.
  1081. ; 12/22/97 13:47:45   Calling host 'MODEM'.
  1082. ; 12/22/97 13:48:17   Successfully connected to host 'MODEM'.
  1083. ; 12/22/97 13:48:20   Transfer of 'C:\SCRIPT.BAT' was successful.
  1084. ; 12/22/97 13:48:23   Executing 'C:\SCRIPT.BAT' on the host...
  1085. ; 12/22/97 13:48:26   Execution of 'C:\SCRIPT.BAT' on the host was successful.
  1086. ; 12/22/97 13:48:26   Disconnecting from host 'MODEM'.
  1087. ; 12/22/97 13:48:33   Calling host 'MODEM'.
  1088. ; 12/22/97 13:49:04   Successfully connected to host 'MODEM'.
  1089. ; 12/22/97 13:49:06   Transfer of 'C:\SCRIPT.BAT' was successful.
  1090. ; 12/22/97 13:49:08   Executing 'C:\SCRIPT.BAT' on the host...
  1091. ; 12/22/97 13:49:12   Execution of 'C:\SCRIPT.BAT' on the host was successful.
  1092. ; 12/22/97 13:49:12   Disconnecting from host 'MODEM'.
  1093. ; 12/22/97 13:49:19   Script completed with 0 error(s).
  1094. ;
  1095. ;
  1096. ;    HOW TO USE A DATA FILE TO CALL MULTIPLE HOST COMPUTERS
  1097. ;    ******************************************************
  1098. ;
  1099. ;    A script can use a text data file to call multiple host computers. This
  1100. ;    can save you from having to create repetitive blocks of code and allow
  1101. ;    you to use the same set of code for each host computer.
  1102. ;
  1103. ;    This script creates it's own data file, the DATA.TXT file. However, the
  1104. ;    remote user would normally create this on their own in the pcANYWHERE
  1105. ;    program directory by using a text editor or word processor. This file
  1106. ;    must be saved as a standard text file.
  1107. ;
  1108. ;    Each line in the data file corresponds to a remote control item of the
  1109. ;    same name. Each of the remote control items in pcANYWHERE requires the
  1110. ;    host computer's phone number, and any logon name or password that may
  1111. ;    also be required. It is not possible to use a list of phone numbers
  1112. ;    instead of a list of host names: the pcANYWHERE Scripting Language
  1113. ;    cannot call a host computer using a phone number but requires a remote
  1114. ;    control item for each host computer that has it's phone number specified
  1115. ;    in it's properties.
  1116. ;
  1117. ;    The DATA.TXT file that this script creates will call the same host
  1118. ;    MODEM twice, and will look like this:
  1119. ;
  1120. ;        MODEM
  1121. ;        MODEM
  1122. ;
  1123. ;    If certain hosts failed to connect or failed in their operations while
  1124. ;    connected to the remote, a specialized DATA.TXT file can be made with
  1125. ;    only the names of the ones to be recalled after the main script has run.
  1126. ;    This is done manually by the remote user. Just create a new DATA.TXT
  1127. ;    file, renaming the old one temporarily, with only the host names to call
  1128. ;    back. After these complete you can then delete the temporary DATA.TXT
  1129. ;    file and rename the original.
  1130. ;
  1131. ;    Troubleshooting note: if you misspell a host computer name in your data
  1132. ;    file, or the host computer name does not exist in the remote control
  1133. ;    section of the remote computer's pcANYWHERE, the error message "File
  1134. ;    Not Found" will appear and the script may end abruptly. If this occurs,
  1135. ;    double check that you have spelled the host computer names correctly and
  1136. ;    that remote control items exist.
  1137. ;
  1138. ;    For information on how to read the data file, please refer to the
  1139. ;    NEXT_HOST subroutine. This subroutine reads the next host to call from
  1140. ;    the data file and assign's it's value to the user-defined HOST variable.
  1141. ;
  1142. ;       
  1143. ;    HOW TO CALL A HOST COMPUTER
  1144. ;    ***************************
  1145. ;
  1146. ;    The only command that can be used to call a host computer is the Session
  1147. ;    Dial command. This command calls the host computer using a pcANYWHERE
  1148. ;    remote control item that has the host computer's phone number, and any
  1149. ;    logon or password information already configured in it's properties.
  1150. ;
  1151. ;    This script uses the subroutine CALL_HOST to call the host computers.
  1152. ;    This subroutine also configures other options for the connection, such
  1153. ;    as the retry value if the connection could not be established. Please
  1154. ;    refer to the CALL_HOST subroutine for more information.
  1155. ;
  1156. ;    Several important notes on calling a host computer with a script are
  1157. ;    listed below:
  1158. ;
  1159. ;    * When connected to a host computer, only specific script commands are
  1160. ;      supported. These include the SessOpr Remote Send, SessOpr Remote Run,
  1161. ;      SessOpr Host Send, SessOpr Host Run and Session End. While other
  1162. ;      commands can be used, they may introduce issues. Also, some script
  1163. ;      commands are designed to be used with online services only, such as
  1164. ;      the Send File and Receive File commands. These type of commands
  1165. ;      should not be used while connected to a host computer.
  1166. ;
  1167. ;    * The session is non-interactive. If the host computer is in use when
  1168. ;      the script calls into it, issues may occur. If you attempt to use the
  1169. ;      host computer remotely while the script runs, issues may occur.
  1170. ;
  1171. ;    * A script cannot interact with a program, nor send text or keystrokes
  1172. ;      to a program. This includes sending keystrokes to data fields, such as
  1173. ;      logon prompts for a network or email program. This is because a script
  1174. ;      cannot set focus on a window or a field so that it can send the text
  1175. ;      to it.
  1176. ;
  1177. ;    * If a connection to a host cannot be established, pcANYWHERE will take
  1178. ;      over and pause until returning control to the script. For example,
  1179. ;      pcANYWHERE will first display "Waiting for Connection" while it is
  1180. ;      trying to call the host computer. After it fails, it will display
  1181. ;      "Timeout Waiting for Connection". Both of these windows will stay on
  1182. ;      the screen for one minute each. Then control will return to the
  1183. ;      script, which is set to wait an additional minute before calling the
  1184. ;      same host back, which it will do three times.
  1185. ;
  1186. ;    
  1187. ;    HOW TO TRANSFER FILES
  1188. ;    *********************
  1189. ;
  1190. ;    Files can be transferred between the remote and host computers by using
  1191. ;    a script. This is performed by the SessOpr Remote Send and the SessOpr
  1192. ;    Host Send commands respectively. (The Send File and Receive File
  1193. ;    commands are only used when connected to an online service.)
  1194. ;
  1195. ;    This script uses the TRANSFER_FILE subroutine to transfer a single file
  1196. ;    from the remote computer to the host computer. In addition to this, the
  1197. ;    source file name is defined by the user-defined SOURCE variable. By
  1198. ;    using a variable, a more robust method for logging the result of
  1199. ;    multiple file transfers can be used instead of creating specific log
  1200. ;    entries. (This script does not use this feature since it only transfers
  1201. ;    one file. However if you have multiple file transfers that take place,
  1202. ;    extra code would not need to be created to record the file transfer's
  1203. ;    results to the log file with the file name that was transferred.)
  1204. ;
  1205. ;    Please refer to the FILE_TRANSFER subroutine for more information. Also,
  1206. ;    for more information on how to perform file transfers, please refer to
  1207. ;    the Symantec Knowledge Base article called "How to Transfer Files to or
  1208. ;    From a Host Computer".
  1209. ;    
  1210. ;    If you are using pcAnywhere 9.0 you will need to add a GoSub @LOOP after
  1211. ;    each file transfer routine.  File transfers will proceed best if you
  1212. ;    use a separate routine for each file transfer such as:
  1213. ;    
  1214. ;    
  1215. ;    @TRANSFER_FILE:               
  1216. ;      SOURCE = "<path><file name>"          
  1217. ;      If $DCD != 1 GoTo @TRANSFER_FILE_LOST 
  1218. ;      $ERROR = 0                 
  1219. ;      SessOpr Remote Send SOURCE "<path><file name>"  
  1220. ;      ERR = $ERROR                 
  1221. ;      If $ERROR < 0 GoTo @TRANSFER_FILE_ERROR  
  1222. ;      LOG = "Transfer of '"             
  1223. ;      StrCat LOG SOURCE             
  1224. ;      LOG2 = "' was successful."         
  1225. ;      StrCat LOG LOG2             
  1226. ;      GoSub @WRITE_LOG             
  1227. ;      RES = 0                 
  1228. ;      GoSub @LOOP                 
  1229. ;                         
  1230. ;    @TRANSFER_FILE1:               
  1231. ;      SOURCE = "<path><file name>"          
  1232. ;      If $DCD != 1 GoTo @TRANSFER_FILE_LOST 
  1233. ;      $ERROR = 0                 
  1234. ;      SessOpr Remote Send SOURCE "<path><file name>"  
  1235. ;      ERR = $ERROR                 
  1236. ;      If $ERROR < 0 GoTo @TRANSFER_FILE_ERROR  
  1237. ;      LOG = "Transfer of '"             
  1238. ;      StrCat LOG SOURCE             
  1239. ;      LOG2 = "' was successful."         
  1240. ;      StrCat LOG LOG2             
  1241. ;      GoSub @WRITE_LOG             
  1242. ;      RES = 0                 
  1243. ;      GoSub @LOOP    
  1244. ;             
  1245. ;      Return        ;Return to main routine at the end of the last
  1246. ;                ;file transfer routine        
  1247. ;
  1248. ;
  1249. ;    Please note that the above example is not meant to be run by itself, but
  1250. ;    has been provided here as an example on how to transfer multiple files with 
  1251. ;     a script.       
  1252. ;
  1253. ;
  1254. ;    HOW TO RUN A PROGRAM
  1255. ;    ********************
  1256. ;
  1257. ;    A program can be run on the remote or host computer while in a session.
  1258. ;    However, if the program is run on a Windows-based computer, the script
  1259. ;    cannot tell when it has finished running. If the script needs to tell
  1260. ;    when the program finishes, a special method of detecting this may need
  1261. ;    to be used. Please refer to the section below called "How to Pause a
  1262. ;    Script While a Program Runs" for more information.
  1263. ;
  1264. ;    A script can use three different commands to run a program:
  1265. ;
  1266. ;    * SessOpr Remote Run, to run a program on the remote computer while in a
  1267. ;      session.
  1268. ;
  1269. ;    * SessOpr Host Run, to run a program on the host computer while in a
  1270. ;      session.
  1271. ;
  1272. ;    * Run, to run a program on the remote computer while not in a session.
  1273. ;
  1274. ;    All three of these function basically the same, with the exception that
  1275. ;    the two SessOpr commands cannot be run outside of a session.
  1276. ;
  1277. ;    It is recommended to specify the full path name of the program to run.
  1278. ;    Also, if it is DOS-based, you may need to specify the command
  1279. ;    interpreter as well. For example, the following command runs the
  1280. ;    MS-DOS EDIT command:
  1281. ;
  1282. ;        Run "COMMAND.COM /C C:\DOS\EDIT.COM"
  1283. ;
  1284. ;    The "COMMAND.COM /C" is the command interpreter. The "/C" switch for the
  1285. ;    command interpreter tells the window to close after it has finished (if
  1286. ;    the command was run from within Windows). Otherwise, the DOS window will
  1287. ;    stay open and the user will need to close it manually.
  1288. ;
  1289. ;    Windows NT must use the START command to run DOS programs, otherwise
  1290. ;    control will not be returned. This is the same as using the "/C", but is
  1291. ;    required for Windows NT.
  1292. ;
  1293. ;
  1294. ;    HOW TO PAUSE A SCRIPT WHILE A PROGRAM RUNS
  1295. ;    ******************************************
  1296. ;
  1297. ;    If a script runs a program on a Windows-based computer, it cannot detect
  1298. ;    when the program finishes. If the script is required to pause while the
  1299. ;    program runs, this can be an issue. The reason a script cannot detect
  1300. ;    when a program finishes is because Windows is a multitasking operating
  1301. ;    system. The script will run the program, but as a separate task in a
  1302. ;    window. The script has no control over this window and cannot detect
  1303. ;    when it closes.
  1304. ;
  1305. ;    Several methods are available which allow a script to pause while a
  1306. ;    program runs, however most are not reliable. The Wait command can pause
  1307. ;    a script, however it is not recommended to use this command while a
  1308. ;    session is active. If a lost connection occurs while the Wait command is
  1309. ;    being used, the remote computer may hang or the script may encounter
  1310. ;    errors. The SessOpr Remote Run and SessOpr Host Run commands using the
  1311. ;    optional Wait parameter only work if the application is run on a DOS-
  1312. ;    based computer. (Not a DOS window run from within Windows.) To correctly
  1313. ;    pause a script while a program runs, a special procedure will need to be
  1314. ;    used.
  1315. ;
  1316. ;    One procedure of pausing a script is to create a loop that uses computer
  1317. ;    cycles, such as incrementing an integer variable. This script uses this
  1318. ;    procedure (the LOOP subroutine) for creating short pauses. However, this
  1319. ;    process is not accurate enough to be used if the script needs to know
  1320. ;    exactly when a program is finished.
  1321. ;
  1322. ;    The best procedure that can pause a script while a program runs is
  1323. ;    described below, which uses a flag file to detect when the program has
  1324. ;    finished running:
  1325. ;
  1326. ;    Step 1. The script runs the program.
  1327. ;
  1328. ;    Step 2. The script goes into a loop where it tries to detect the
  1329. ;        existence of a flag file which is created by the program when
  1330. ;        it finishes. If it cannot find the file, then it continues to
  1331. ;        search until it is found or a set number of searches have been
  1332. ;        completed.
  1333. ;
  1334. ;    Step 3. After the script detects the flag file, it then continues where
  1335. ;         it left off.
  1336. ;
  1337. ;    This script uses the CHECK_FLAG subroutine to perform this procedure.
  1338. ;    The following is an excerpt from the CHECK_FLAG subroutine:
  1339. ;
  1340. ; @CHECK_FLAG:                 ; Subroutine used to pause the script.
  1341. ;   LOOP = 0                 ; Reset the value of LOOP to 0.
  1342. ;
  1343. ; @CHECK_FLAG_FILE:             ; Subroutine used find flag file.
  1344. ;   GoSub @LOOP                 ; Pause script for five seconds.
  1345. ;   LOOP = LOOP + 1             ; Increment the value of LOOP.
  1346. ;   If LOOP == 24 GoTo @CHECK_FLAG_ERROR  ; If LOOP takes too long, abort.
  1347. ;   If $DCD != 1 GoTo @CHECK_FLAG_LOST  ; If lost connection, end loop.
  1348. ;   $ERROR = 0                 ; Reset the value of $ERROR to 0.
  1349. ;   SessOpr Host Send "C:\PCA.FLG" "C:\PCA.FLG"  ; Attempt file transfer.
  1350. ;   If $ERROR == -8 GoTo @CHECK_FLAG_FILE  ; If file not found, loop.
  1351. ;   If $ERROR < 0 GoTo @CHECK_FLAG_OTHER  ; If other error, end loop.
  1352. ;
  1353. ;    The @CHECK_FLAG subroutine has a single line. This resets the value of
  1354. ;    the user-defined LOOP variable to a zero. The LOOP variable is
  1355. ;    discussed in more detail below.
  1356. ;
  1357. ;    The @CHECK_FLAG_FILE subroutine is where the actual check for the
  1358. ;    existence of the flag file occurs at. The command lines for this
  1359. ;    excerpt are described below:
  1360. ;
  1361. ;    1. GoSub @LOOP. This pauses the script for approximately five seconds
  1362. ;       by branching to the LOOP subroutine. This is important to use
  1363. ;       because otherwise the script will loop too quickly while checking
  1364. ;       for the flag file and could result in memory issues on the remote
  1365. ;       computer.
  1366. ;
  1367. ;    2. LOOP = LOOP + 1. This increments the LOOP variable by one. When the
  1368. ;       script loops too many times, the CHECK_FLAG subroutine will
  1369. ;       automatically timeout, as described below.
  1370. ;
  1371. ;    3. If LOOP == 24 GoTo @CHECK_FLAG_ERROR. If the CHECK_FLAG_FILE
  1372. ;       subroutine has looped twenty-four times, about two minutes, abort
  1373. ;       the subroutine because an error may have occurred that is preventing
  1374. ;       the flag file from being detected. If this check does not occur, the
  1375. ;       script may hang and go into an infinite loop. By changing the number
  1376. ;       24 to a larger or smaller number, the script will wait a longer or
  1377. ;       shorter amount of time. This is based on a five second pause when the
  1378. ;       script branches to the LOOP subroutine times the number that it
  1379. ;       checks here; 24 times 5 seconds is two minutes.
  1380. ;
  1381. ;    4. The connection status of the modems is checked. If the remote
  1382. ;       computer is no longer connected to the host computer, the subroutine
  1383. ;       is aborted.
  1384. ;
  1385. ;    5. The value of $ERROR is reset to zero before trying to detect the flag
  1386. ;       file by file transferring it to the remote computer.
  1387. ;
  1388. ;    6. The script attempts to transfer the flag file PCA.FLG from the host
  1389. ;       computer to the remote computer.
  1390. ;
  1391. ;    7. If the file was not found (error -8), then the subroutine loops back
  1392. ;       to the beginning and continues until it is able to transfer the file
  1393. ;       or the LOOP variable times out.
  1394. ;
  1395. ;    8. If any other error occurred, the script aborts.
  1396. ;
  1397. ;    This script uses the flag file PCA.FLG. Since this file will at some
  1398. ;    point exist on both the remote and host computers, it needs to be
  1399. ;    deleted before the CHECK_FLAG subroutine runs. Otherwise, the
  1400. ;    CHECK_FLAG subroutine will detect it on the host computer, and assume
  1401. ;    that the program is finished running. The RUN_FILE subroutine is used
  1402. ;    to delete the PCA.FLG files on both the remote and host computers
  1403. ;    before it runs the sample application SCRIPT.BAT file on the host
  1404. ;    computer, then it branches to the CHECK_FLAG subroutine until the
  1405. ;    real PCA.FLG file has been detected.
  1406. ;
  1407. ;    The SCRIPT.BAT file creates the PCA.FLG file when it finishes. All that
  1408. ;    this file does is the following:
  1409. ;
  1410. ;        @ECHO OFF
  1411. ;        C:
  1412. ;        CD \
  1413. ;        DIR /A
  1414. ;        DIR >PCA.FLG
  1415. ;
  1416. ;    The first line sets the echo off for output from any following commands.
  1417. ;    The second line changes to the C: drive. The third line changes to the
  1418. ;    root drive of the C: drive. The fourth line then displays the directory
  1419. ;    of the C: root directory and all files found in it. After it finishes,
  1420. ;    it creates the dummy file PCA.FLG by piping the contents of the
  1421. ;    directory to the file name by using a DIR command.
  1422. ;
  1423. ;    A batch file only needs the following three lines of code to create the
  1424. ;    flag file:
  1425. ;
  1426. ;        C:
  1427. ;        CD \
  1428. ;        DIR >PCA.FLG
  1429. ;
  1430. ;    The CHECK_FLAG subroutine requires a batch file to be used so that it
  1431. ;    can then create the flag file after it has finished with it's normal
  1432. ;    operations. However, if you have the ability to create a Visual BASIC
  1433. ;    or other executable application, it can also be used so long as when it
  1434. ;    finishes, it creates the flag file. However, it is up to you to create
  1435. ;    your own batch file or executable application.
  1436. ;
  1437. ;
  1438. ;    USING "INFINITE" LOOPS
  1439. ;    **********************
  1440. ;    
  1441. ;    Using a subroutine that loops an "infinite" amount of times (over and
  1442. ;    over again), or loops so many times that it takes a long period of time
  1443. ;    to complete, is not usually recommended. Such infinite loops are very
  1444. ;    likely to cause issues on the remote computer, such as causing the
  1445. ;    script to hang, or cause an Unexpected program error message.
  1446. ;
  1447. ;    If you need a subroutine to perform an infinite loop, there are two
  1448. ;    things which you can do to minimize how many issues may occur. This
  1449. ;    includes using a check variable that stops the loop if it's value
  1450. ;    is exceeded, and using a sub-loop to pause the looping for a short
  1451. ;    period of time to allow the remote to process other computer cycles.
  1452. ;
  1453. ;    The CHECK_FLAG subroutine in this script uses the LOOP variable as
  1454. ;    a check variable. Each time the subroutine loops, the check variable
  1455. ;    is incremented by one. Once this variable is 24 or more, the script
  1456. ;    then assumes an error has occurred and aborts the loop.
  1457. ;
  1458. ;    The CHECK_FLAG subroutine also uses a sub-loop to pause it from
  1459. ;    continually looping without delay. At the beginning of the subroutine,
  1460. ;    the LOOP subroutine is called. This subroutine also performs loops,
  1461. ;    but does so very quickly by incrementing a variable 40,000 times to
  1462. ;    simulate approximately a five second delay. After this loop finishes,
  1463. ;    control returns to the CHECK_FLAG subroutine.
  1464.