4

I would like my (W7 Pro) VPN to start up automatically when I connect to my work wifi, but not others. Is this possible? I still want to be able to connect manually when I'm elsewhere, but avoid getting my work emails coming at me unless I'm at work (i.e. on work wifi), or choose to have it.

I found Rasdial but need to know how to trigger it upon connection to a particular network.

2 Answers 2

2

You can run a script to do this. Just put it in Startup folder, or run it manually, etc.

This Powershell script I wrote should do the trick. Just edit the IP for the gateway on your work WiFi and replace notepad with your rasdial command.

if (!(Test-Connection 192.168.20.1 -Quiet)){
Start-Sleep -s 10 
}

Else {
# replace the command below with your rasdial string
& 'C:\Windows\notepad.exe'
Exit
}
5
  • Have I missed something? Doesn't that only make the connection - it doesn't automate the connection when a specific Wi-Fi is connected to does it? May 27, 2014 at 15:32
  • It will. It will ping the IP of his WiFi gateway at work. If its found, it will initiate the connection. Otherwise it sleeps for 10 seconds. You can alse change the IP to -Computername <something> as well.
    – Keltari
    May 27, 2014 at 15:38
  • But it would only run once when you log in wouldn't it? Most likely, you would already be logged in but only changing networks - at least that's how most people seem to work. Running your script as per my answer should work. May 27, 2014 at 15:41
  • well it depends on his usage.
    – Keltari
    May 27, 2014 at 15:42
  • I would sometimes be logged on, sometimes starting up at time of connection so I would try and implement the script with the task scheduler.
    – James N
    May 27, 2014 at 15:49
1

See the Answer for this question. You can run a "scheduled" task based on an event trigger. This could either start your VPN directly or via a script depending on the software in use.

2
  • This works in conjunction with the script above except it also triggers after my VPN and other connections are triggered - obviously the script evaluates that my host is available. I can see making it work by complicating the script to include updating a text file with an 'already connected' flag and just updating this whenever I also lose connection. Is there anything simpler? I'm not familiar with Powershell but am with Python, so when I have time I may create something with that.
    – James N
    May 28, 2014 at 7:32
  • Not done this myself so I'm guessing somewhat I'm afraid. However, I don't think you need the IP address check in the above script if you are executing from an Event as you already know you are connecting to a known network. Change the IF to NOT run if the VPN is already active by only running if the IP of the VPN is NOT found. Sorry too many negatives, did that make sense? May 28, 2014 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .