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
- Open Notepad or your preferred text editor.
Step 2: Create the Script
- 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
- 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, enterRunIfVpnConnected.ps1
. - In the
Save as type
dropdown, selectAll Files (*.*)
to ensure the file is saved with a.ps1
extension. - Click
Save
.
- Go to
Step 4: Open PowerShell and Navigate to the Script’s Directory
- Open PowerShell:
- Press
Win + X
and selectWindows 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:
- Press
cd C:\Users\YourUsername\Desktop
Step 5: Run the Script
- Execute the script by typing:
.\RunIfVpnConnected.ps1
[ END]
Instructions for macOS:
Step 1: Open a Text Editor
- Open a text editor.
Step 2: Create the Script
- 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
- Save the file with a
.sh
extension. For example, if you are usingnano
:- Press
Ctrl + X
to exit. - Press
Y
to confirm the save. - Enter the filename, e.g.,
RunIfVpnConnected.sh
.
- Press
- If using
TextEdit
:- Go to
Format
>Make Plain Text
. - Go to
File
>Save
. - In the
Save As
field, enterRunIfVpnConnected.sh
. - Select the location where you want to save the script.
- Ensure the file is saved with a
.sh
extension. - Click
Save
.
- Go to
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
- Open a text editor. You can use editors like
nano
,gedit
, orvim
.
Step 2: Create the Script
- 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
- Save the file with a
.sh
extension. For example, if you are usingnano
:- Press
Ctrl + X
to exit. - Press
Y
to confirm the save. - Enter the filename, e.g.,
RunIfVpnConnected.sh
.
- Press
- 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, enterRunIfVpnConnected.sh
. - Ensure the file is saved with a
.sh
extension. - Click
Save
.
Step 4: Make the Script Executable
- 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
- Execute the script by typing:
./RunIfVpnConnected.sh