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>	Carriage return                              <lf>	Line feed                              <match>"abcdef"	Waits for match to "abcdef"                              <ignore>	Ignores the rest of the response                              <?>	Wildcard character                              <hNN>	Used to represent a hexadecimal value containing the digits NN                              <diagnostics>	Displays a diagnostic message box                              OK=value	Defines the expected response                              COMMAND=value<cr>	Sends the text string "value"                              NoResponse	No response is expected                              CONNECT=value	Terminates the script when the "value" is received                              ERROR_NO_CARRIER=value	Checks for the loss of the modem carrier                              ERROR_DIAGNOSTICS=value	Checks for diagnostic messages                              LOOP=value	Loop waiting for a match value                              

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




; Send the USERNAME



;wait for "PASSWORD:" prompt


; Send the PASSWORD and ignore response



; Wait for "Annex>" send the PPP command




; Wait for the Annex to start up PPP mode

CONNECT=<match>"Switching to PPP"



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.


; get to the host name prompt



; log on to the CIS network


; check for username prompt


; enter the username


; check for the password prompt


; enter the password


; finish


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.


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





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





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:


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.
  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.