Simple vbs script to first map a drive and then unmap it again
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "I:", "PATH_OF_SHARE","True","jdoe","jdoepassword"
objNetwork.RemoveNetworkDrive "I:"
Slightly more advanced vbs script mapping a drive without a drive letter and then unmapping it again if exists
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "", "PATH_OF_SHARE","True","jdoe","jdoepassword"
Set objDrives = objNetwork.EnumNetworkDrives
If objDrives.Count > 0 Then
For i = 0 To objDrives.Count-1 Step 2
If objDrives.Item(i+1) = "PATH_OF_SHARE" Then
objNetwork.RemoveNetworkDrive "PATH_OF_SHARE", True, True
i=objDrives.Count-1
End If
Next
End If
Hope this helps you on your way