Knowledgebase : VPN
Using Windows Task Scheduler to create a Killswitch
Posted by Administrator on 21 December 2019 06:54 pm

Instead of providing another complicated method that requires messing with the Windows Firewall or Comodo Firewall rules, an easier way is by using the Task Scheduler that is built into Windows. This method doesn’t involve installing any third party software and uses the native event checking feature in Windows which is more stable and barely uses any noticeable CPU or memory usage. All you need to do is create a new task that will automatically close your BitTorrent client software when the OS detects a termination on your VPN connection.

a) Press the Start button, type Task Scheduler and run it.

run task scheduler

b) Click Action on the menubar and select “Create Task“.

c) Type in anything for the name of this new task that you’re going to create. Tick the checkbox for “Run with highest privileges“.

d) Go to the Trigger tab and click the New button.

e) Click the drop down menu for Begin the Task and select “On an event“.

task scheduler trigger

f) Select RasClient for Source, enter the Event ID as 20226 and click OK.

g) Go to the Actions tab and click the New button.

h) Ensure that the action is “Start a program“.

i) At the program/script input box, enter taskkill.exe and at the add arguments box, enter /f /im filename.exe. You’ll need to replace the filename.exe with the executable file that you want to terminate. For example, uTorrent would be utorrent.exe, Deluge is deluge.exe, qBittorrent is qbittorrent.exe, etc. Click OK to save the changes.

task scheduler action

k) Optionally go to the Conditions tab and check on the Power options. By default, the option “Start the task only if the computer is on AC power” is enabled and you may want to disable this setting. When your computer is on battery power, this task won’t run when your VPN connection is lost and causing your BitTorrent client to continue download through the direct Internet connection revealing your real IP address.

Additional Tip: The idea above can be extended to disabling all network connections when the VPN connection is lost instead of forcefully terminating running programs. At step (i), replace the taskkill.exe with powershell.exe. Then at the arguments box, enter Get-NetAdapter | Disable-NetAdapter -Confirm:$false.

powershell disable all network adapter

To automatically re-enable all network adapters, you can run the following command line as administrator.

powershell.exe Get-NetAdapter | Enable-NetAdapter -Confirm:$false