How Can We Help?

Run a specific app when VPNUK is connected

If you would like to ruin a specific app when the vpnuk connection is connected and do not allow the app to run when the vpn is not connected you can create a command line service check.

Instructions for Windows:

Step 1: Open a Text Editor

  1. Open Notepad or your preferred text editor.

Step 2: Create the Script

  1. Copy the following PowerShell script into your text editor and update the path to the executable you want to run:

# Check if OpenVPN is running
$service = Get-Service -Name "OpenVPNServiceInteractive"
if ($service.Status -eq "Running") {
# Run your program
# Change the path below to the executable you want to run, e.g., C:\Users\YourUsername\Desktop\your_program.exe
Start-Process "C:\path\to\your\program.exe"
} else {
Write-Output "VPN is not connected. Program will not run."
}

Step 3: Save the Script

  1. In your text editor:
    • Go to File > Save As.
    • Navigate to the location where you want to save the script.
    • In the File name field, enter RunIfVpnConnected.ps1.
    • In the Save as type dropdown, select All Files (*.*) to ensure the file is saved with a .ps1 extension.
    • Click Save.

Step 4: Open PowerShell and Navigate to the Script’s Directory

  1. Open PowerShell:
    • Press Win + X and select Windows PowerShell or open PowerShell from the Start menu.
    • Navigate to the directory where you saved the script. For example, if you saved it on your Desktop:

cd C:\Users\YourUsername\Desktop

Step 5: Run the Script

  1. Execute the script by typing:

.\RunIfVpnConnected.ps1

[ END]

Instructions for macOS:

Step 1: Open a Text Editor

  1. Open a text editor.

Step 2: Create the Script

  1. Copy the following Bash script into your text editor and update the path to the executable you want to run:

!/bin/bash
# Check if OpenVPN is running
if pgrep -x "openvpn" > /dev/null
then
# Run your program
# Change the path below to the executable you want to run, e.g., /Users/YourUsername/Desktop/your_program
/path/to/your/program
else
echo "VPN is not connected. Program will not run."
fi

Step 3: Save the Script

  1. Save the file with a .sh extension. For example, if you are using nano:
    • Press Ctrl + X to exit.
    • Press Y to confirm the save.
    • Enter the filename, e.g., RunIfVpnConnected.sh.
  2. If using TextEdit:
    • Go to Format > Make Plain Text.
    • Go to File > Save.
    • In the Save As field, enter RunIfVpnConnected.sh.
    • Select the location where you want to save the script.
    • Ensure the file is saved with a .sh extension.
    • Click Save.

Step 4: Make the Script Executable

Open terminal and navigate to the directory where you saved the script. For example, if you saved it on your Desktop:

cd ~/Desktop

Make the script executable by running:

chmod +x RunIfVpnConnected.sh

Execute the script by typing:

./RunIfVpnConnected.sh

[END]

Instructions for Linux:

Step 1: Open a Text Editor

  1. Open a text editor. You can use editors like nano, gedit, or vim.

Step 2: Create the Script

  1. Copy the following Bash script into your text editor and update the path to the executable you want to run:

#!/bin/bash

# Check if OpenVPN is running
if pgrep -x "openvpn" > /dev/null
then
# Run your program
# Change the path below to the executable you want to run, e.g., /home/YourUsername/Desktop/your_program
/path/to/your/program
else
echo "VPN is not connected. Program will not run."
fi

Step 3: Save the Script

  1. Save the file with a .sh extension. For example, if you are using nano:
    • Press Ctrl + X to exit.
    • Press Y to confirm the save.
    • Enter the filename, e.g., RunIfVpnConnected.sh.
  2. If using a graphical text editor, go to File > Save As:
    • Navigate to the location where you want to save the script.
    • In the File name field, enter RunIfVpnConnected.sh.
    • Ensure the file is saved with a .sh extension.
    • Click Save.

Step 4: Make the Script Executable

  1. Open a terminal and navigate to the directory where you saved the script. For example, if you saved it on your Desktop:

cd ~/Desktop

Make the script executable by running:

chmod +x RunIfVpnConnected.sh

Step 5: Run the Script

  1. Execute the script by typing:

./RunIfVpnConnected.sh

Table of Contents