ThinWorld Citrix Knowledgebase

Wednesday, 8 July 2009

The local device name has a remembered connection to another network resource

I was getting the following error message when using a VB script to perform network drive mappings. The error occured if the drive letter was already mapped.

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