Pages

Monday, July 31, 2017

Using Command Line explorer.exe Net to Re-establish Network Shares After VPN is Established Through a Captive Portal

As shown in Using Net Use to Re-establish Network Shares After VPN is Established Through a Captive Portal Net use can be easily used with Windows Task Scheduler to reconnect the shares after establishing a VPN connected over a captive portal. An alternative method is to create a .cmd file using explorer.exe to reconnect the shares and the Windows Management Instrumentation Command-line (WMIC) to find and terminate the explorer processes


Create a .cmd file similar to

start "RECONNECT_HOME_DRIVE" /MIN explorer.exe H:\
start "RECONNECT_SHARE_DRIVE" /MIN explorer.exe X:\

WMIC PROCESS WHERE "CommandLine like '%%explorer.exe /factory%%'" DELETE

Use the same process described in Using Net Use to Re-establish Network Shares After VPN is Established Through a Captive Portal to find and create the event trigger. The steps from the other post are included below.

Start the Windows Event Viewer and look for a useable event for the trigger. In my case, under Applications and Services logs I found an event logged upon successfully establishing the VPN. 

After finding a suitable event, right click on it and select Attach Task to This Event.

Give it a name and description. Select Next
When an Event is logged. No updates. Select Next
Define the action. Select Start a Program radio button. Select Next
Browse to the Program/Script (command file) created and provide any optional arguments. Select Next.
Review the event and trigger and select Finish.

Now, log off and log back in. If all is correct then upon successfully establishing the VPN the script will be triggered and the shares will be reconnected.


No comments:

Post a Comment