-
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
-
@Nareese Hey. Thanks for writing. And glad you found this little script useful. I tried to avoid
rasdial
because (in my case) it required that credentials be provided in the script, something I felt was unnecessary (and potentially unsafe) due to the VPN interface already being defined. But if it works for you, thats awesome!Can you please share which version you're on?
Regarding
rasphone
config not being applied. My suggestion is to check if your interface is defined for systemwide use or only for the current user. Afterwards verify the system or user config ofrasphone
.