Using Task Scheduler to map network drives once connected to VPN

By | January 22, 2021

The problem arises that users don’t always have the correct drive mappings in place when they connect to a VPN. This problem is easily overcome when using OpenVPN as you can easily provide a script to process on successful connection/disconnection.

To summarise (for OpenVPN), just add the script into the relevant OpenVPN config folder, and provided it meets the correct naming syntax it will execute as expected. The script must be named the same as the connection, followed by _Down or _Up. Example – if my OpenVPN configuration is called FloridaOffice.ovpn I will name my scripts FloridaOffice_Down.bat and FloridaOffice_Up.bat

Now for Windows 10 client VPN connections – there doesn’t seem to be any easy way to run a script on connection. Instead use Task Scheduler and create a new task. In my test, I set the trigger to be the system log event, source: RasMan, Event ID:20267

Once you have created and tested your event you can export this to be imported onto other computers. I have seen various PowerShell scripts out there that can be customised but this seems an easier route to go and could even be setup by the user themselves.