Silently re-connect to already mapped network drive

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‘]]”

  1. Replace abc by any name, just to identify your task.
  2. c:test.bat should be replaced by path to your batch file which you need to run on vpn connection
  3. 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

  1. 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
  2. Simply change drive to the mapped drive letter in batch file (works for me on my office vpn)
  3. 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

 

Reference Links:

Be First to Comment

Leave a Reply