I am trying to write a quick and dirty script for a test lab which will disconnect and reconnect persistent drive mappings. The script is as follows:
Set objDrvs = GetObject("winmgmts:").InstancesOf("Win32_NetworkConnection")
for each obj in objDrvs
strDrive = obj.LocalName
strDMapping = obj.RemoteName
On Error Resume Next
objWshNet.RemoveNetworkDrive strDrive, True, True 'Force removal
If Err<>0 Then
'Log Error
Wscript.Echo "Error disconnecting"& strDrive
Err.Clear
End If
objWshNet.MapNetworkDrive strDrive, strDMapping
If Err<>0 Then
'Log Error
Wscript.Echo "Error remapping "& strDrive & "("& strDMapping &")"
Err.Clear
Else
Wscript.Echo "Remapped "& strDrive & "("& strDMapping &")"
End If
Next
The script fails to disconnect any drive mapping and therefore fails to reconnect it. Can anyone advise me where I am going wrong? The ERR value is 424 is that make any sense to anyone. I want to run this on logon but I just running it interativley at the moment.
Cheers
Jacqui
