Apologies to the owner of the list :-) mis copied the email address.  I meant to send the message below.


Jacqui Hurst <[EMAIL PROTECTED]> wrote:
Date: Wed, 26 Apr 2006 14:21:03 +0100 (BST)
From: Jacqui Hurst <[EMAIL PROTECTED]>
Subject: RE: [ActiveDir] OT: _vbscript_ to disconnect and reconnect persistent drive mappings
To: [EMAIL PROTECTED]

 Will this method, and if so, allow me to enumerate each drive setting detail and remap the drive?
 
I was hoping that someone might tell me what was wrong with my code rather than re-writing it.  The only reason I say this is not being a 'natural' coder I almost have to start from scratch with all new methods suggested.  That being said all help is appreciated.
 
Jacqui
 
 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kennedy, Jim
Sent: 26 April 2006 13:31
To: [email protected]
Subject: RE: [ActiveDir] OT: _vbscript_ to disconnect and reconnect persistent drive mappings
 
 
Lot of work and code there to remove drives...try this...
 
Option Explicit
Dim WshNetwork
 
on error resume next
 
Set WshNetwork = WScript.CreateObject("WScript.Network")
 
WshNetwork.RemoveNetworkDrive "m:"
WshNetwork.RemoveNetworkDrive "n:"
WshNetwork.RemoveNetworkDrive "o:"
WshNetwork.RemoveNetworkDrive "p:"
WshNetwork.RemoveNetworkDrive "q:"
WshNetwork.RemoveNetworkDrive "r:"
WshNetwork.RemoveNetworkDrive "s:"
WshNetwork.RemoveNetworkDrive "t:"
WshNetwork.RemoveNetworkDrive "u:"
WshNetwork.RemoveNetworkDrive "v:"
WshNetwork.RemoveNetworkDrive "w:"
WshNetwork.RemoveNetworkDrive "x:"
WshNetwork.RemoveNetworkDrive "y:"
WshNetwork.RemoveNetworkDrive "z:"
 
...add all the letters you want.  :)
 

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