-
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
-
Glad you found it useful.
Right, thanks for pointing that out. Must have forgotten to include it. I've just updated
vpn_auto_reconn.ps1
.