Announcement

Collapse
No announcement yet.

disconnect mapped drives before mapping?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • disconnect mapped drives before mapping?

    hey guys,

    i have a little login script that maps a network drive according to AD group

    Code:
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("Wscript.Network")
    
    strUserPath = "LDAP://" & objSysInfo.UserName
    Set objUser = GetObject(strUserPath)
    
    For Each strGroup in objUser.MemberOf
        strGroupPath = "LDAP://" & strGroup
        Set objGroup = GetObject(strGroupPath)
        strGroupName = objGroup.CN
    
     Select Case strGroupName
    
    
    Rem Map network drive 1
       Case "drive1"
        objNetwork.MapNetworkDrive "q:", "\\server\share" , TRUE
    
    Rem Map network drive 2
       Case "drive2"
        objNetwork.MapNetworkDrive "r:", "\\server\share" , TRUE
    
    Rem MAP network drive 3
       Case "drive3"
        objNetwork.MapNetworkDrive "j:", "\\server\share", TRUE
        
    Rem MAP network drive  4
       Case "drive4"
        objNetwork.MapNetworkDrive "n:", "\\server\share", TRUE
        End Select
    
    Next
    Rem Quit the Script
    wscript.quit
    what would be the best way to disconnect the mapped drives i.e Q:, R:, J:, N:

    before remapping them?

    thanks!

  • #2
    Re: disconnect mapped drives before mapping?

    RemoveNetworkDrive
    (documented http://ss64.com/vb/driverm.html)

    If you are not sure which drives are connected, enumerate them first
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: disconnect mapped drives before mapping?

      firstly, change the "UpdateProfile" argument in objNetwork.MapNetworkDrive "<d>:", "\\server\share" , TRUE
      to: objNetwork.MapNetworkDrive "<d>:", "\\server\share", FALSE
      so it will not map the drives persistently.

      And when you use the statement .RemoveNetworkDrive, the 3rd argument "bUpdateProfile" should be TRUE.


      example;
      Code:
      Set objSysInfo = CreateObject("ADSystemInfo")
      Set objNetwork = CreateObject("Wscript.Network")
      
      On Error Resume Next
      For Each strDrive In array("Q:","I:","K:","N:")
         objNetwork.RemoveNetworkDrive strDrive, TRUE, TRUE
      Next
      On Error Goto 0
      
      strUserPath = "LDAP://" & objSysInfo.UserName
      Set objUser = GetObject(strUserPath)
      arrGroups = objUser.memberOf
      
      If Not IsEmpty(arrGroups) Then
         ' http://www.rlmueller.net/MemberOf.htm
      
         If (TypeName(arrGroups) = "String") Then
           strGroupPath = "LDAP://" & arrGroups
           Set objGroup = GetObject(strGroupPath)
           MapIf objGroup.CN
         Else
           For Each strGroup In arrGroups
             strGroupPath = "LDAP://" & strGroup
             Set objGroup = GetObject(strGroupPath)
             MapIf objGroup.CN
           Next
         End If
      End If
      
      Sub MapIf(GroupName)
         On Error Resume Next
         Select Case LCase(GroupName)
      
         Case LCase("drive1")
           objNetwork.MapNetworkDrive "q:", "\\server\share1", FALSE
      
         Case LCase("drive2")
           objNetwork.MapNetworkDrive "r:", "\\server\share2", FALSE
      
         Case LCase("drive3")
           objNetwork.MapNetworkDrive "j:", "\\server\share3", FALSE
      
         Case LCase("drive4")
           objNetwork.MapNetworkDrive "n:", "\\server\share4", FALSE
      
         End Select
      End Sub

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X