-
Open VPN Settings
-
Open the Settings app by pressing
Windows + I
on your keyboard. -
Or go to Network & Internet.
-
-
Add a VPN Connection
-
Click on VPN on the left-hand side.
-
Click the Add a VPN connection button.
-
After that, proceed with the usual configuration steps, such as entering the server details, VPN type, and login information.
Using rasphone
fetches the already saved credentials. Unlike rasdial
, which requires that credentials be provided.
-
Locating the
.pbk
file:- For connections saved for the current user:
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Network\Connections\Pbk
- system file — for connections saved for all users:
C:\ProgramData\Microsoft\Network\Connections\Pbk
-
Open
rasphone.pbk
in any text editor. -
Change
PreviewUserPw=1
toPreviewUserPw=0
. This disables the prompt before dialing. -
Then change
ShowDialingProgress=1
toShowDialingProgress=0
. This hides the dialing progress window, so the connection process won't be visible. -
Finally change
ShowMonitorIconInTaskBar=1
toShowMonitorIconInTaskBar=0
. This prevents the monitor icon from appearing in the taskbar when the connection is active. -
Save the file.
Please find the script as files below.
Download and save to a desired folder, that will remain static for the lifetime of the script.
Installs BurntToast
if not already installed. For sending out notifications after 10 consecutive failed connection attempts.
-
Open in any text editor
-
Change the VPN name
$vpnName
-
You can also localize
Send-Notification
inside functionCheck-VpnConnection
-
Save
-
Open in any text editor
-
Change the VPN name
$vpnName
-
Save
-
Create a New Shortcut
-
Right-click on the Desktop (or in the folder where you want the shortcut).
-
Select New > Shortcut from the context menu.
-
-
Enter the Command
-
In the "Create Shortcut" wizard, you’ll be prompted to type the location of the item.
-
Enter the following command:
powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\path\to\script\vpn_auto_reconn_notify.ps1"
-
- Click Next.
-
Name the Shortcut
-
Enter a name for your shortcut.
-
Click Finish.
-
Verify that the shortcut works by running it and checking if the VPN connects.
Simply move the shortcut you just created into one of the following folders.
- Location for the current user:
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
- Location for all users:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
-
Then Sign out of the current user or restart the computer.
-
And verify that the VPN auto connects:
-
By checking if it connects on login/startup
-
By disconnecting it manually and monitoring for automatic reconnect within ~10-40 seconds
-
Thanks for the quick response.
I am on Win11. My VPN connection is set up through the standard Win11 VPN setup in the Settings panel, my credentials are entered there, and are configured to be saved there, and thus rasdial does not require them to be supplied on the command line. Only the connection name is required. Also probably worthy of note, when rasphone pops the connect dialog, the saved credentials, both username and password, are pre-filled in the dialog, so I just have to hit connect, so it's definitely picking up the correct connection. I did check that it was not a system vs user issue, as the system config directory is empty. So as I said, no clue what's going on there, it should be working. Regardless, rasdial works great for me, it was more just an FYI for you and others in case someone else runs into this weirdness.