Executing Scripts on VPN Connection
This can be achieved by creating a task in task sceduler to run on vpn connection (using event id).
Type the below command in command prompt after replacing the data accordingly
schtasks /create /F /TN “abc” /TR “C:test.bat” /SC ONEVENT /EC Application /MO ” *[System[(Level=4 or Level=0) and (EventID=20225)]] and *[EventData[Data=’VPN NAME‘]]”
- Replace abc by any name, just to identify your task.
- c:test.bat should be replaced by path to your batch file which you need to run on vpn connection
- VPN Name should be replaced by the name of the vpn connection, after connection of which you wish to execute the batch file above.
Once you have created the task, you can view the task in task scheduler @ Windows Control Panel > Administrative Tools > Task Sceduler
Reconnecting the Share
Either of these 3 methods should work this out
- Have a batch file to open an explorer window minimized to the share path and then auto close it based on the Window Title using taskill
- Simply change drive to the mapped drive letter in batch file (works for me on my office vpn)
- Try using the command, replacing z by drive letter mapped and \servershare by share path
net use z: \servershare 2> nul
For option – 2, use these commands in batch file
Start /min explorer x: timeout 3 /nobreak Taskkill /fi "windowtitle"
here replace X with the share drive letter and replace windowtitle with the title of the window when you open the share when it is connected
- Answered Post By Northwind Traders on http://social.technet.microsoft.com/Forums/en-US/w7itpronetworking/thread/4c2bea2a-5c06-4ef0-83c3-85e1c27a7dad/
- TaskScheduler Task Execution on VPN connect event from this article – http://simpleverse.wordpress.com/2010/10/06/add-routes-on-vpn-connect-with-powershell-and-task-scheduler/
Be First to Comment