How to Automate Your RAS Login

Microsoft's Remote Access Services (RAS) is a powerful connectivity tool for wide-area connections for numerous applications, including remote connectivity to a Windows NT Server and connectivity from a Windows NT Workstation or Server system to the Internet, CompuServe, and other online systems. Unfortunately, RAS has little integrated support for non-Microsoft connections. For example, if you use the standard RAS setup to dial in to the Internet or CompuServe, you have to invoke the RAS Terminal interface to manually log in to the service. Fortunately, Microsoft lets you automate this process. To automate logins, you can create scripts and store them in the switch.inf file. This text file is in the %SYSTEMROOT%\SYSTEM32\RAS directory (%SYSTEMROOT% is the drive and topmost directory for your Windows NT software; e.g., C:\WINNT35.

Because the default switch.inf file contains several explanations, suggestions, and examples, get acquainted with this file before you start editing it. Also, back up the file before you start altering it.

TABLE 1: Here is a list of RAS script commands.
<cr><b> Carriage return</b>
<lf><b> Line feed</b>
<match>"abcdef"<b>      Waits for match to "abcdef"</b>
<ignore><b>     Ignores the rest of the response</b>
<?><b>  Wildcard character</b>
<hNN><b>        Used to represent a hexadecimal value containing the digits NN</b>
<diagnostics><b>        Displays a diagnostic message box</b>
OK=value<b>     Defines the expected response</b>
COMMAND=value<cr><b>    Sends the text string "value"</b>
NoResponse<b>   No response is expected</b>
CONNECT=value<b>        Terminates the script when the "value" is received</b>
ERROR_NO_CARRIER=value<b>       Checks for the loss of the modem carrier</b>
ERROR_DIAGNOSTICS=value<b>      Checks for diagnostic messages</b>
LOOP=value<b>   Loop waiting for a match value</b>

To create a new script, you define a section header (a title) for it. The section header can be anything--it is only a configuration item in your RAS phone book entry. Then you need to know exactly what the connecting network expects to send and receive during the login process. To get this information, use the RAS Terminal interface, turn on screen capture, and complete the login process manually. You can then develop an automated script from the information you record in the capture file.

RAS Scripts
Each script starts with a section header and then has command and response entries. Table 1 lists and explains the various commands. To document the script, you can add comments, which start with a semicolon.

Below is a typical RAS login script. For this script to work, you must replace the strings myusername and mypassword with a valid username and password.

\[Xylogics Annex Three\]

; Wait until you get the "USERNAME:" prompt

COMMAND=

ERROR_NO_CARRIER=<match>"NO CARRIER"

OK=<match>"AME:"

; Send the USERNAME

COMMAND=MYUSERNAME<cr>

ERROR_NO_CARRIER=<match>"NO CARRIER"

;wait for "PASSWORD:" prompt

OK=<match>"ORD:"

; Send the PASSWORD and ignore response

COMMAND=MYPASSWORD<cr>

ERROR_NO_CARRIER=<match>"NO CARRIER"

; Wait for "Annex>" send the PPP command

OK=<match>"nnex>"

COMMAND=PPP<cr>

ERROR_NO_CARRIER=<match>"NO CARRIER"

; Wait for the Annex to start up PPP mode

CONNECT=<match>"Switching to PPP"

ERROR_DIAGNOSTICS=<cr><lf><Diagnostics>

ERROR_DIAGNOSTICS=<lf><cr><lf><Diagnostics>

Below is a more complex RAS script for a Point-to-Point Protocol (PPP) login to CompuServe Information Service (CIS). You must replace the XXXXX,XXXX string with your CIS ID and the mypassword string with your password.

\[CompuServe\]

; get to the host name prompt

COMMAND=<cr>

OK=<match>":"

; log on to the CIS network

COMMAND=CIS<cr>

; check for username prompt

OK=<match>":"

; enter the username

COMMAND=XXXXX,XXXX/GO:PPPCONNECT<cr>

; check for the password prompt

OK=<match>":"

; enter the password

COMMAND=mypassword<cr>

; finish

OK=<ignore>

If you have problems with your script running before the remote system is ready to respond, add a delay of two seconds. Insert the following code at the start of your script below the section header.

COMMAND=

To skip two lines of text from the remote system, enter the following commands.

COMMAND=

OK=<ignore>

COMMAND=

OK=<ignore>

Some providers have a long login banner before the username prompt. The LOOP command lets you ignore such a banner before you get the username prompt. Enter

COMMAND=

OK=<match>"sername"

LOOP=<ignore>

COMMAND=myusername<cr>

Some PPP/Serial Line Internet Protocol (SLIP) servers require you to send a carriage return to wake the server. To do so, add this command after the section header:

COMMAND=<cr>

Activating Your Script
After you create a login script and store it in the switch.inf file, to activate it, follow these steps:

  1. Launch RAS applet.
  2. Create a new phone book entry or edit an existing entry.
  3. Make sure the "Authenticate using the current username and password" box is not checked on the initial edit screen. You can use your current login username and password for RAS authentication if the PPP server you are dialing into supports PPP Password Authentication Protocol (PAP)/Challenge Handshake Authentication Protocol (CHAP) authentication. If this option is not checked, you get a prompt for a domain name, username, and password. Unfortunately, switch.inf scripting does not let you automate this information. Instead, you press OK when this prompt appears and let your script handle the authentication.
  4. Click Advanced if the Security button is not visible.
  5. Click the Security button.
  6. Make sure the "Accept any authentication including clear text" box is checked.
  7. Select the section header for the switch.inf script you added to the switch.inf file. This selection is in the After Dialing list box.
  8. Click OK to confirm.
  9. Exit RAS, and restart it to activate the script.
  10. Restart the RAS applet, select your phone book entry, and click the Dial button.

To troubleshoot a RAS login script, enable the device.log file. Reviewing it after a failed login gives you an idea of where to modify your switch.inf script to make your login script work correctly. To activate the device.log file:

  1. Run the regedt32.exe registry editor program.
  2. Modify HKEY_LOCAL_MACHINE\SYSTEM\Current
    ControlSet\Services\RasMan\Parameters.
  3. Change the value of Logging to 1.

Logging will not begin until you exit RAS and restart the RAS program. The commands sent to your modem and the responses will be logged in a file named device.log in the %SYSTEMROOT%\SYSTEM32\RAS directory.