Restoring network connection

// Use Windows Explorer to restore disconnected network drive before
// running a program that accesses data files on the disconnected drive.

Dim process_id, number
Dim window_handle, number

Run( "explorer k:\data", "", process_id )
// Wait 10 seconds to allow the Explorer to restore connection
Wait( 10 )
// Try to close Explorer gracefully (this is better than killing the process.
// However, ProcessKill statement guarantees process termination, while a keystroke
// is just sent to an active window, which can change anytime)
SendKeys( "{ALT}{F4}" )

// Wait 2 more seconds
Wait( 2 )
// Check whether Explorer is still running or not
ProcessGetWindow( process_id, window_handle )
isGreater( window_handle, 0, running)

if( running, KILL, DO_MAIN_JOB )
KILL:
ProcessKill( process_id )

DO_MAIN_JOB:
// Do the main job here
// Run ...