Schnizzle
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.Netw ork")
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\_A dministrat ion Department"
Case "Building Department"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_B uilding Department"
Case "Clerks and Bylaw Dept"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_C lerks Department"
Case "Finance Dept"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_F inance Department"
Case "Fire Dept"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_F ire Department"
Case "Public Works and Roads Dept"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_P ublic Works Department"
Case "Recreation Department"
objNetwork.MapNetworkDrive "X:", "\\cityview\home\shared\_R ecreation 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
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.Netw
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
If TypeName(objUser.MemberOf)
strGroup = ""
ElseIf TypeName(objUser.MemberOf)
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
Case "Building Department"
objNetwork.MapNetworkDrive
Case "Clerks and Bylaw Dept"
objNetwork.MapNetworkDrive
Case "Finance Dept"
objNetwork.MapNetworkDrive
Case "Fire Dept"
objNetwork.MapNetworkDrive
Case "Public Works and Roads Dept"
objNetwork.MapNetworkDrive
Case "Recreation Department"
objNetwork.MapNetworkDrive
'Map V: Drive for CityView - for members part of the CityView users Group
Case "CityView Users"
objNetwork.MapNetworkDrive
End Select
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks! Glad I could help ;-)
ASKER