With TorGuard, you get the most powerful VPN application on the market. We have numerous security features that make us stand out like IP leak protection, Stealth VPN + Stealth Proxy, an organized server selection, customizable startup settings, and a bunch of other useful features.

Today, however, we are here to talk about VPN startup scripts, one of TorGuard’s most unique features inside the TorGuard client. Advanced VPN users may find this additional level of modification very useful.

With startup scripts, you can automate common VPN tasks. Startup scripts give you the ability connect to file servers, openweb pages, open apps, and control any application that is scriptable. TorGuard is compatible with both Mac, Windows and Linux computers. With startup scripts, you can add custom actions via Batch/VBS Scripts (Windows) or AppleScripts (Mac). To add your custom script in the TorGuard app, select “More Settings…” then click the “Scripts” tab. Select your desired scripts then click the “Execute scripts” checkbox and click save.

Windows Example Scripts

How to Mount a Network Drive

 Do you want to mount a nework drive? Use this simple script.

@echo off

net use Z: \\server\share

This batch script can be used to mount a network drive to a remote file server. If you have a different drive than “Z”, simply swap it out for “C” or “D”. Place this command in your connected script. Then when you want to make a disconnect script, use this line of code to disconnect the network drive when VPN connection is terminated.

@echo off

net use Z: /delete

 How to Open Webpage 

If you want to create a script to automatically open your default web browser, and go to a web page, simply type and use the following script.

URL = "http://www.torguard.net"

Set objShell = CreateObject("Wscript.Shell")

objShell.Run(URL)

 How to Close Program

If you want to automatically kill a program or close it down, then you can create a script with the following code. (You can also use the built in app killswitch in the TorGuard app.) Perhaps you want to disconnect a program when your VPN disconnects. Simply replace the file .exe with what program you want. In this case, we used the example “notepad.exe”.

Option Explicit

Dim objWMIService, objProcess, colProcess

Dim strComputer, strProcessKill

strComputer = "."

strProcessKill = "'notepad.exe'"

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" _

& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _

("Select * from Win32_Process Where Name = " & strProcessKill )

For Each objProcess in colProcess

objProcess.Terminate()

Next

WSCript.Echo "Just killed process " & strProcessKill _

& " on " & strComputer

WScript.Quit

' End of WMI Example of a Kill Process

Apple Example Scripts

How to Connect/Disconnect to File Server

 If you want an AppleScript to connect to a AFP file server, use the following code.

tell application "Finder"
mount volume "afp://serveraddress/sharename" as user name "username" with password "password"
end tell

If you want to use an AppleScript to connect to a SMB/CIFS (Windows) server, use the following code for your script.

tell application "Finder"
mount volume "smb://serveraddress/sharename" as user name "username" with password "password"
end tell

 How to Open Web Page

 If you want to make a script to open a webpage, use the following code. Just replace the webpage URL location with your chosen webpage.

tell application "Finder" to open location "https://www.torguard.net"

 How to Play Sound

 You can use an AppleScript to play a sound file. Just make sure to point the script to the right file location. Replace the example file location with your own!

set playsound to POSIX path of ("/System/Library/Sounds/Ping.aiff")
do shell script ("afplay " & playsound & " > /dev/null 2>&1 &")/
 

How to Run Shell Script

 

If you want to use an AppleScript to run a shell script, you can use this script.

 
do shell script "/path/to/script.sh"

You can also run the following script if you want to run a shell script with admin privaleges.

do shell script "/path/to/script.sh" user name "username" password "password" with administrator privileges

TorGuard also offers its own built in killswitch if you want to use that feature, but you can also customize your killswitch options as we discussed in the script to close programs or disable networks.

These are just a few examples of possible VPN scripts, however the possibilities are endless. Feel free to share your custom VPN scripts in the TorGuard VPN Forum!

Share this post