-
Open VPN Settings
-
Open the Settings app by pressing
Windows + Ion 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
.pbkfile:- 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.pbkin any text editor. -
Change
PreviewUserPw=1toPreviewUserPw=0. This disables the prompt before dialing. -
Then change
ShowDialingProgress=1toShowDialingProgress=0. This hides the dialing progress window, so the connection process won't be visible. -
Finally change
ShowMonitorIconInTaskBar=1toShowMonitorIconInTaskBar=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-Notificationinside 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
-
Hey, just wanted to drop a note here that this is the only solution I could get to work for restarting a VPN connection coming out of sleep. Multiple solutions exist for getting a VPN to start on startup, but wake from sleep is not a startup, and is a whole different beast. I tried a lot of things, none worked. This does, obviously. The only issue I found, for reasons I completely don't understand, is I could not get this script to dial the connection without showing the dialing dialog and making me press connect. I verified that I had PreviewUserPw=0 (and I even also set PreviewDomain=0 in case that was causing it), and it still popped the dialog. The solution I came to was to change "rasphone -d $vpnName" to "rasdial $vpnName". This works "silently-ish", and does not pop the dialog. So, success! Thank you!