Windows PPTP/L2TP Redial

Share This!

This article will guide you on how to setup your existing L2TP or PPTP VPN connection to launch automatically when your computer starts.

 

Before going any further, you should already have a working L2TP or PPTP connection set up on your computer and you should be able to connect to our service using this without any problems.

If you haven’t set it up yet, please refer to our Get Started instructions

 

Note: We’ve tested this on Windows 10, 8.1, and 8. Versions of Windows prior to Windows 8 do not need this script for redialing PPTP/L2TP.


Getting Started


You would need to run Windows PowerShell once and enable the PowerShell to load scripts so that we can run our redial program. 


To do this, please press on the Windows key + Q on your keyboard and search for PowerShell. Once that PowerShell is shown, please right click on it and select Run As Administrator.


Once you’ve done so, you will see a window as below:


This is the main window for Windows PowerShell



In order to enable scripts to be executed in Windows PowerShell, you would have to key in the line below and press Enter:


Set-ExecutionPolicy Unrestricted


Command to enable PowerShell to load external scripts

Once this is done, you should see a prompt as below. Key in Y and then Enter.

The prompt that is shown when you key in the command


Obtaining the script


You can download our script file in which you would need to set up later.

VPN Auto Redial Script File Download

Note: You would have to Right Click and click on Save Link As / Save As to download.

Alternatively, you can create the PowerShell script without downloading anything else. (Skip this and proceed to Editing the script if you’ve already downloaded our PowerShell script above)


First, open up Notepad, and then copy and paste the contents below to the Notepad:

    

for ($i = 1; $i -le 2; $i++) # Runs this program over and over until your VPN fails to connect
{
    $vpn_status = rasdial.exe "MPN GBR" "Your MPN Username" "Your MPN Password" # connects to the VPN connection with your username and password

    # If your VPN name is set to MPN only or any other name, please change MPN USA to the respective VPN name that you've used, keeping all the quotes intact
    # Replace Your VPN Username and Your VPN Password to your username and password, keeping all the quotes intact

    if ($vpn_status -like '*successfully*') # This line checks if the connection is successful
    {
	$time = 30 # By default, your VPN will try and check the connection after after 30 seconds, change the value to alter the time

        Write-Host "You've connected to our VPN successfully"
        $i = 1;
        Start-Sleep -s $time
    }

    else
    {
        if ($vpn_status -like '*error*') # Checks if the connection is NOT successful and stops the script
        {
            Write-Host "Error connecting, please copy the error message that you've got below and email us: `n" -ForegroundColor Yellow

            $vpn_status

            $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") # Puts a pause to the program instead of auto-exiting it so you can copy and paste the error message
        }
    }
}

    

Then, you would have to refer to the next step (Editing the script) to edit the content according to the VPN connection that you’re trying to connect and your VPN username and password with us. 

 

When it’s done, you would have to click on File > Save As and select All Files under the Save As Type drop down menu

 

Saving the script to the appropriate file

Set the file name to VPN AutoRedial.ps1 or other file name (it needs to end with .ps1) and then click on Save.


Editing the script


After downloading (or creating) the script, please edit the script file by clicking the file that you’ve downloaded.

 

You should see the contents of the script in Notepad as follow:

     

for ($i = 1; $i -le 2; $i++) # Runs this program over and over until your VPN fails to connect
{
    $vpn_status = rasdial.exe "MPN GBR" "Your MPN Username" "Your MPN Password" # connects to the VPN connection with your username and password

    # If your VPN name is set to MPN only or any other name, please change MPN USA to the respective VPN name that you've used, keeping all the quotes intact
    # Replace Your VPN Username and Your VPN Password to your username and password, keeping all the quotes intact

    if ($vpn_status -like '*successfully*') # This line checks if the connection is successful
    {
	$time = 30 # By default, your VPN will try and check the connection after after 30 seconds, change the value to alter the time

        Write-Host "You've connected to our VPN successfully"
        $i = 1;
        Start-Sleep -s $time
    }

    else
    {
        if ($vpn_status -like '*error*') # Checks if the connection is NOT successful and stops the script
        {
            Write-Host "Error connecting, please copy the error message that you've got below and email us: `n" -ForegroundColor Yellow

            $vpn_status

            $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") # Puts a pause to the program instead of auto-exiting it so you can copy and paste the error message
        }
    }
}

     

If you’re about to connect to other country (for example, USA) then you should set it to MPN USA instead of MPN GBR (at the 3rd line that starts with $vpn_status). Do keep the quotes intact as well. 

 

Note: If you have a VPN connection in which you’ve setup the name of the PPTP or L2TP connection to be just MPN, then you should change “MPN GBR” to just “MPN”. The connection name that comes after rasdial.exe should reflect on what VPN connection that you currently have whereas “Your MPN Username” and “Your MPN Password” should be replaced with your username and password respectively, while keeping the quotes intact as well.


By default, this script will always try and check if your L2TP and PPTP VPN connection is connected every 30 seconds. If you would like to set it to check the connection every 1 minute instead, change the value (in seconds) from 30 to 60 at line number 10 of the script.

 

Once you’ve done editing the file, please click on File and then followed by Save.


Running the script


Right click on the script file and then choose Run with PowerShell.


Right clicking on the script and select Run with PowerShell

 

You should see en empty PowerShell Window. If you’re successfully connected to the VPN, you’ll see the message below appear in your PowerShell Window a few moments later:

 

The PowerShell script is running and trying to connect to vpn

 

If there’s any error while trying to connect the VPN connection, you would be presented with the error message. 


Disabling redial


To stop the automatic redial, please exit the PowerShell by clicking on the X button at the upper right hand side of the window. Do note that by exiting this window, your current VPN connection wouldn’t be disconnected.

Any problems?


If you have any problems or can’t get connected, please email us at [email protected]. We’ll get back to you as soon as possible to assist you.