How do I map a drive that has already been mapped 
Author Message
 How do I map a drive that has already been mapped

I am trying to remove a mapped drive and assign a new mapping to the same
drive letter, however, I am being receiving an error:

"An attempt was made to remember a device that had been previously
remembered."

Below is the code.  Thanks for your help

Ken Ross

Const OldServer="\\PDXNT_02\"
Const NewServer="\\PDXNTFS1\"

Dim Shell, User, NetObj, NetConnect, NetDrvLtr, TxtRead
Dim TxtCheck, NetPath, DrvLtr, DrvLtr2
Dim RegWordPath, WordPath

Wscript.Echo "Starting Migration..."

' Instantiate Shell object to obtain user id and access to registry
Set Shell = Wscript.CreateObject("Wscript.Shell")
User = Shell.ExpandEnvironmentStrings("%UserName%")
User = Ucase(User)

 ' Create Network Object for obtaining NetDrives List
Set NetObj = Wscript.CreateObject("Wscript.Network")

 ' Obtain list of Network Drive Connections
Set NetConnect = NetObj.EnumNetworkDrives()

 ' Set variable to blank
DrvLtr = ""

Wscript.Echo "Removing Home Dirs Connected to PDXNT_02..."
Wscript.Echo "Connecting new Home drives to PDXNTFS1..."

' Locate User Home Dir and Modify
For NetDrvLtr = 0 to NetConnect.Count - 1

NetPath = ""
TxtRead = NetConnect(NetDrvLtr)
TxtRead = Ucase(TxtRead)

TxtCheck = Right(TxtRead, 1)
If TxtCheck = ":" Then
DrvLtr = TxtRead
DrvLtr2 = TxtRead
Else
NetPath = TxtRead
End If

If NetPath = OldServer & User Then

' Disconnect Existing drives from PDXNT_02
NetObj.RemoveNetworkDrive DrvLtr

' Reconnect drives to PDXNTFS1
NetObj.MapNetworkDrive DrvLtr2, NewServer & User

End If

Next



Sun, 30 Jun 2002 03:00:00 GMT  
 How do I map a drive that has already been mapped

Hi,

You can do this that way.

    drive = fso.getDrive(lecteur)

    if len(drive) = 0 then
        call net.MapNetworkDrive(lecteur, _
                            "\\" & Computer & "\" & Share, _
                            false, User, pass)
    else
        call net.RemoveNetworkDrive(lecteur)
        call net.MapNetworkDrive(lecteur, _
                            "\\" & Computer & "\" & Share, _
                            false, User, pass)
    end if

Hope this will help

Quote:
> -----Message d'origine-----

> Publi : mercredi 12 janvier 2000 18:50
> Publi dans : wsh
> Conversation : How do I map a drive that has already been mapped
> Objet : How do I map a drive that has already been mapped

> I am trying to remove a mapped drive and assign a new mapping
> to the same
> drive letter, however, I am being receiving an error:

> "An attempt was made to remember a device that had been previously
> remembered."

> Below is the code.  Thanks for your help

> Ken Ross

> Const OldServer="\\PDXNT_02\"
> Const NewServer="\\PDXNTFS1\"

> Dim Shell, User, NetObj, NetConnect, NetDrvLtr, TxtRead
> Dim TxtCheck, NetPath, DrvLtr, DrvLtr2
> Dim RegWordPath, WordPath

> Wscript.Echo "Starting Migration..."

> ' Instantiate Shell object to obtain user id and access to registry
> Set Shell = Wscript.CreateObject("Wscript.Shell")
> User = Shell.ExpandEnvironmentStrings("%UserName%")
> User = Ucase(User)

>  ' Create Network Object for obtaining NetDrives List
> Set NetObj = Wscript.CreateObject("Wscript.Network")

>  ' Obtain list of Network Drive Connections
> Set NetConnect = NetObj.EnumNetworkDrives()

>  ' Set variable to blank
> DrvLtr = ""

> Wscript.Echo "Removing Home Dirs Connected to PDXNT_02..."
> Wscript.Echo "Connecting new Home drives to PDXNTFS1..."

> ' Locate User Home Dir and Modify
> For NetDrvLtr = 0 to NetConnect.Count - 1

> NetPath = ""
> TxtRead = NetConnect(NetDrvLtr)
> TxtRead = Ucase(TxtRead)

> TxtCheck = Right(TxtRead, 1)
> If TxtCheck = ":" Then
> DrvLtr = TxtRead
> DrvLtr2 = TxtRead
> Else
> NetPath = TxtRead
> End If

> If NetPath = OldServer & User Then

> ' Disconnect Existing drives from PDXNT_02
> NetObj.RemoveNetworkDrive DrvLtr

> ' Reconnect drives to PDXNTFS1
> NetObj.MapNetworkDrive DrvLtr2, NewServer & User

> End If

> Next



Sun, 30 Jun 2002 03:00:00 GMT  
 How do I map a drive that has already been mapped

RE:How do I map a drive that has already been mappedThe code implies error trapping is enabled all the time...

A slightly better way is to limit the lifetime of the error trapping to only enclose statements where you expect and can reasonably handle an error (and actually check for an error).

On Error Resume Next
drive = fso.getDrive(lecteur)
if Err then
    Err.Clear
    On Error GoTo 0
    'drive letter is in use
    'actually 68 is the err.number
    'if not a valid drive letter (as a number)
    'the err.number is 5
else
    On Error GoTo 0
    'drive letter not is use
end if

--
Michael Harris

  Hi,

  You can do this that way.

      drive = fso.getDrive(lecteur)

      if len(drive) = 0 then
          call net.MapNetworkDrive(lecteur, _
                              "\\" & Computer & "\" & Share, _
                              false, User, pass)
      else
          call net.RemoveNetworkDrive(lecteur)
          call net.MapNetworkDrive(lecteur, _
                              "\\" & Computer & "\" & Share, _
                              false, User, pass)
      end if

  Hope this will help

  > -----Message d'origine-----

  > Publi : mercredi 12 janvier 2000 18:50
  > Publi dans : wsh
  > Conversation : How do I map a drive that has already been mapped
  > Objet : How do I map a drive that has already been mapped
  >
  >
  > I am trying to remove a mapped drive and assign a new mapping
  > to the same
  > drive letter, however, I am being receiving an error:
  >
  > "An attempt was made to remember a device that had been previously
  > remembered."
  >
  > Below is the code.  Thanks for your help
  >
  > Ken Ross
  >
  > Const OldServer="\\PDXNT_02\"
  > Const NewServer="\\PDXNTFS1\"
  >
  > Dim Shell, User, NetObj, NetConnect, NetDrvLtr, TxtRead
  > Dim TxtCheck, NetPath, DrvLtr, DrvLtr2
  > Dim RegWordPath, WordPath
  >
  > Wscript.Echo "Starting Migration..."
  >
  > ' Instantiate Shell object to obtain user id and access to registry
  > Set Shell = Wscript.CreateObject("Wscript.Shell")
  > User = Shell.ExpandEnvironmentStrings("%UserName%")
  > User = Ucase(User)
  >
  >  ' Create Network Object for obtaining NetDrives List
  > Set NetObj = Wscript.CreateObject("Wscript.Network")
  >
  >  ' Obtain list of Network Drive Connections
  > Set NetConnect = NetObj.EnumNetworkDrives()
  >
  >  ' Set variable to blank
  > DrvLtr = ""
  >
  > Wscript.Echo "Removing Home Dirs Connected to PDXNT_02..."
  > Wscript.Echo "Connecting new Home drives to PDXNTFS1..."
  >
  > ' Locate User Home Dir and Modify
  > For NetDrvLtr = 0 to NetConnect.Count - 1
  >
  > NetPath = ""
  > TxtRead = NetConnect(NetDrvLtr)
  > TxtRead = Ucase(TxtRead)
  >
  > TxtCheck = Right(TxtRead, 1)
  > If TxtCheck = ":" Then
  > DrvLtr = TxtRead
  > DrvLtr2 = TxtRead
  > Else
  > NetPath = TxtRead
  > End If
  >
  > If NetPath = OldServer & User Then
  >
  > ' Disconnect Existing drives from PDXNT_02
  > NetObj.RemoveNetworkDrive DrvLtr
  >
  > ' Reconnect drives to PDXNTFS1
  > NetObj.MapNetworkDrive DrvLtr2, NewServer & User
  >
  > End If
  >
  > Next
  >
  >
  >
  >
  >



Sun, 30 Jun 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Name already exists error on map drive.

2. Name already exists error trying to map drive.

3. get drive size from network network mapped drives

4. Cant remove Drive Mapped in VBScript

5. Mapping Drives

6. map drive per global group

7. Removing Mapped Drives

8. Map/unmap a drive?

9. Network Drive mapping?

10. Drive mapping

11. Drive Mapping

12. Mapping Drives based on NT global groups

 

 
Powered by phpBB® Forum Software