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.
%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
- Step 1
1.Home laptop 192.168.140.10 runs rasdial "Office VPN"
- Step 2
2.rasdial reads server vpn.example.com from the phonebook
- Step 3
3.IKEv2 request (UDP 500) goes via home router and internet
- Step 4
4.Office firewall allows UDP 500 / TCP 443
- Step 5
5.VPN server verifies user jdoe and replies
- Step 6
6.PPP adapter Office VPN gets 192.168.240.5: Successfully connected
Verify with ipconfig (PPP adapter) and route print -4
- Step 1
1.DNS cannot resolve vpn.example.com: error 868
- Step 2
2.Firewall blocks UDP 500 / TCP 443: error 800 / 809
- Step 3
3.Reaches server but wrong user/password: error 691
- Step 4
4.Entry name not in the phonebook: error 623
| Error | Meaning | Check |
|---|---|---|
| 623 | Phonebook entry not found | Entry name, quotes, /PHONEBOOK |
| 691 | Wrong username / password | Credentials |
| 868 | Server name not resolved by DNS | DNS, server address |
| 800 / 809 | Server unreachable / port blocked | Firewall, 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.
rasdial /?USAGE: rasdial.exe entryname [username [password|*]] [/DOMAIN:domain] [/PHONE:phonenumber] [/CALLBACK:callbacknumber] [/PHONEBOOK:phonebookfile] [/PREFIXSUFFIX] rasdial.exe [entryname] /DISCONNECT rasdial.exerasdialrasdial n120-labNo 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.
rasdial n120-lab labuser *rasdial n120-lab /PHONEBOOK:n120-empty.pbkPassword:$ 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.
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.
Add-VpnConnection -Name "Office VPN" -ServerAddress vpn.example.com -TunnelType Ikev2 -RememberCredentialrasdial "Office VPN"120.4 rasdial: disconnect (6)
rasdial n120-lab /DISCONNECTNo 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.
- Step 1
1.rasdial "Office VPN" /DISCONNECT
- Step 2
2.Laptop sends a disconnect request to the VPN server
- Step 3
3.Tunnel closes: PPP adapter and VPN routes removed
- Step 4
4.Command completed successfully; traffic uses the home internet again
120.5 Scripting rasdial
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)
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| Switch | Opens |
|---|---|
| -d entry | Dial dialog |
| -h entry | Hang up |
| -e entry | Edit properties |
| -r entry | Delete entry |
| -a | New entry wizard |
| -f file.pbk | Use 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).