The local device name has a remembered connection to another network resource
The local device name has a remembered connection to another network resource
The VBScript was written to detect if the mapped drive already existed and to unmap it before mapping it again. A snapshot of the code is :
Set objWshNetwork = CreateObject("WScript.Network")
'Remove the drive mapping
objWshNetwork.RemoveNetworkDrive strDriveLetter, FORCE, FORCE
' Create the drive mapping
objWshNetwork.MapNetworkDrive strDriveLetter, StrUNCPath,True
The problem seemed to be that the RemoveNetworkDrive command did not delete all the registry entries for the network drive from under HKCU\Network\driveletter
To resolve the issue i added a registry delete command to delete the key before i tried to perform the mapping. I used the following code to perform this.
(note : StrDriverLetter need sto be set somewhere in your script)
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "Network\" & Left(StrDriveLetter)
objReg.DeleteKey HKEY_CURRENT_USER, strKeyPath