Error 424 is object required.

 

Try this:

 

Option Explicit

‘On Error Resume Next

 

Dim objWshNet

Set objWshNet = Wscript.CreateObject(“WScript.Network”)

 

Dim objDrvs

Set objDrvs = GetObject("winmgmts:").InstancesOf("Win32_NetworkConnection")

 

Dim obj

Dim strDrive

Dim strDMapping

 

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

 

 

Thanks,
Brian Desmond

[EMAIL PROTECTED]

 

c - 312.731.3132

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jacqui Hurst
Sent: Wednesday, April 26, 2006 7:26 AM
To: [email protected]
Subject: [ActiveDir] OT: _vbscript_ to disconnect and reconnect persistent drive mappings

 

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

 

Reply via email to