Link to home
Start Free TrialLog in
Avatar of Schnizzle
SchnizzleFlag for Canada

asked on

Script to detect if mapped drive already exists

Hello,

I have a script running that is mapping a network drive but in some cases where the mapped drive already exists, the script generates a "Local Device already in use" error. below is the code for the script and it is line 49 that it hangs up on when trying to map the V: drive. Any help is appreciated!

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
 
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
 
If TypeName(objUser.MemberOf) = "Empty" Then
      strGroup = ""
ElseIf TypeName(objUser.MemberOf) = "String" Then
      strGroup = objUser.MemberOf
      CheckGroup strGroup
Else
      For Each strGroup In objUser.MemberOf
            CheckGroup strGroup
      Next
End If
 
Sub CheckGroup(strGroupDN)
    strGroupPath = "LDAP://" & strGroupDN
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN
    'wscript.echo strGroupName
 
    Select Case strGroupName
               
        Case "Office Admin Dept"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Administration Department"
 
      Case "Building Department"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Building Department"
 
      Case "Clerks and Bylaw Dept"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Clerks Department"
 
      Case "Finance Dept"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Finance Department"
 
      Case "Fire Dept"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Fire Department"      
 
      Case "Public Works and Roads Dept"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Public Works Department"
 
      Case "Recreation Department"
            objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_Recreation Department"

'Map V: Drive for CityView - for members part of the CityView users Group
      Case "CityView Users"
            objNetwork.MapNetworkDrive "V:", "\\cityview\cityview"  

  End Select
End Sub
SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Schnizzle

ASKER

Thanks Guys. I used the On error resume next but the other suggestion is good too. Anyway, i'm all sorted now! thanks for your quick response.
Thanks! Glad I could help ;-)