SkillPilotAI

rasdial and rasphone

Windows saves every VPN, PPPoE or dial-up connection as an entry in a phonebook (.pbk) file. rasdial dials, lists and disconnects these entries from the command line; rasphone opens the same entries in GUI dialogs. Both are the simplest built-in way to script a Windows VPN.

120.1 What it does and where it runs

  • rasdial = command-line client of the Remote Access Service: dial / status / disconnect.
  • rasphone = GUI dialogs with switches -d -h -e -r -a -f.
  • Both are built into System32 and run in CMD and PowerShell.
Output
%APPDATA%\Microsoft\Network\Connections\Pbk\rasphone.pbk       (current user)%ProgramData%\Microsoft\Network\Connections\Pbk\rasphone.pbk    (all users)

120.2 How a VPN dial works

rasdial: the journey of a VPN dial
  1. 1.Home laptop 192.168.140.10 runs rasdial "Office VPN"

  2. 2.rasdial reads server vpn.example.com from the phonebook

  3. 3.IKEv2 request (UDP 500) goes via home router and internet

  4. 4.Office firewall allows UDP 500 / TCP 443

  5. 5.VPN server verifies user jdoe and replies

  6. 6.PPP adapter Office VPN gets 192.168.240.5: Successfully connected

Verify with ipconfig (PPP adapter) and route print -4

Where it fails: error codes
  1. 1.DNS cannot resolve vpn.example.com: error 868

  2. 2.Firewall blocks UDP 500 / TCP 443: error 800 / 809

  3. 3.Reaches server but wrong user/password: error 691

  4. 4.Entry name not in the phonebook: error 623

ErrorMeaningCheck
623Phonebook entry not foundEntry name, quotes, /PHONEBOOK
691Wrong username / passwordCredentials
868Server name not resolved by DNSDNS, server address
800 / 809Server unreachable / port blockedFirewall, NAT, UDP 500/4500, TCP 443

120.3 rasdial: status and connect (6)

Run on a Windows 11 PC without admin rights; no real VPN was dialled.

Terminal
rasdial /?
Output
USAGE:  rasdial.exe entryname [username [password|*]]    [/DOMAIN:domain]    [/PHONE:phonenumber] [/CALLBACK:callbacknumber]    [/PHONEBOOK:phonebookfile] [/PREFIXSUFFIX]   rasdial.exe [entryname] /DISCONNECT   rasdial.exe
Terminal
rasdialrasdial n120-lab
Output
No connectionsCommand completed successfully.$ rasdial n120-labRemote Access error 623 - The system could notfind the phone book entry for this connection.
  • rasdial with no arguments lists connected entries (No connections = none up).
  • n120-lab does not exist in the phonebook, so error 623.
Terminal
rasdial n120-lab labuser *rasdial n120-lab /PHONEBOOK:n120-empty.pbk
Output
Password:$ rasdial n120-lab /PHONEBOOK:n120-empty.pbkRemote Access error 623 - The system could notfind the phone book entry for this connection.
  • * instead of the password gives a prompt, so the password is not saved in command history.
  • /PHONEBOOK uses your own .pbk file instead of the default one.
Output
rasdial                              connected entriesrasdial "Office VPN"                 saved credentialsrasdial "Office VPN" jdoe P@ssw0rd   user + passwordrasdial "Office VPN" jdoe *          password prompt/DOMAIN:CORP                         Windows domain/PHONE:5551234                       number / server/CALLBACK:5559876                    callback number/PHONEBOOK:C:\vpn\corp.pbk           other .pbk file/PREFIXSUFFIX                        TAPI prefix/suffix
  • Entry names with spaces need double quotes; no username/password = saved credentials.
  • /DOMAIN, /PHONE, /CALLBACK are mostly for old dial-up setups.
  • Create entries with PowerShell Add-VpnConnection, then dial the same name with rasdial.
PowerShell
Add-VpnConnection -Name "Office VPN" -ServerAddress vpn.example.com -TunnelType Ikev2 -RememberCredentialrasdial "Office VPN"

120.4 rasdial: disconnect (6)

Terminal
rasdial n120-lab /DISCONNECT
Output
No connectionsCommand completed successfully.
  • rasdial <entry> /DISCONNECT hangs up that entry; No connections = nothing with that name is up.
  • /DISCONNECT without a name works only when exactly one connection is up: in scripts always pass the entry name.
rasdial /DISCONNECT
  1. 1.rasdial "Office VPN" /DISCONNECT

  2. 2.Laptop sends a disconnect request to the VPN server

  3. 3.Tunnel closes: PPP adapter and VPN routes removed

  4. 4.Command completed successfully; traffic uses the home internet again

120.5 Scripting rasdial

Terminal
rasdial "Office VPN" /DISCONNECT          rem named entry hang uprasdial /DISCONNECT                       rem only when exactly one connection is uprasdial "Office VPN" && route print -4rasdial "Office VPN" jdoe * || echo failschtasks /create /tn VPNup /sc onlogon /tr "rasdial \"Office VPN\""ipconfig | findstr /i "PPP"
  • rasdial returns a non-zero exit code on failure (e.g. 691, 623), so && / || work in batch files.

120.6 rasphone switches (GUI dialogs) (5)

Terminal
rasphone -d "Office VPN"     rem dial dialograsphone -h "Office VPN"     rem hang uprasphone -e "Office VPN"     rem propertiesrasphone -r "Old VPN"        rem delete entryrasphone -a                  rem new entry wizardrasphone -f C:\vpn\corp.pbk -d "Office VPN"   rem -f = other phonebook file
SwitchOpens
-d entryDial dialog
-h entryHang up
-e entryEdit properties
-r entryDelete entry
-aNew entry wizard
-f file.pbkUse another phonebook file

Each switch opens a dialog, so the video did not run rasphone on the office PC.

120.7 Common mistakes

  • rasdial Office VPN without quotes: entry = Office, username = VPN, so error 623.
  • Putting the password in plain text in scripts: use * or saved credentials.
  • Using /DISCONNECT without a name when several connections are up.
  • Thinking rasdial is only for dial-up modems: it dials IKEv2, SSTP and L2TP entries too.

120.8 Interview tips

  • VPN auto-connect at logon: Add-VpnConnection -RememberCredential, then schtasks /sc onlogon running rasdial "Office VPN".
  • Check rasdial's exit code in scripts (691, 623...).
  • Know the codes: 623 entry, 691 credentials, 868 DNS, 800/809 reachability/port.
  • Entries live in rasphone.pbk under %APPDATA% (user) or %ProgramData% (all users).