Basically we can create a Batch file and place the below code
echo check if G drive exists and if exists delete it or unmap it
IF EXIST G: GOTO DELG
:OPENG
REM ----------------------------------------Copying to Shared Folder-------------------------------------------
net use G: \\100.100.100.100\d$\Shared Password /user:UserId /persistent:YES
echo Drive G is successfully connected
echo Please wait Copying files from source to the destination
Copy/Y Source Path G:\
echo Files Copied successfully
net use G: /DELETE