[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1621
  • Last Modified:

Windows Script Host Error 80070055

Hi there guys.....i'm having a small problem with the script below.Now so far it works well and maps the specified drives to the users.But a few users experience an error 80070055..The Local device is already in use, Source:WSHNetwork.MapNetworkDrive.They click the ok button to the error, and find that the drive is mapped on their machine.I have checked for duplicate drive letters but nada.I'm on a deadline guys and would appreciate ur help thanks.
Option Explicit
Dim objSysInfo
Dim objNetwork
Dim strUserPath
Dim objUser
Dim strGroup
Dim strGroupPath
Dim objGroup
Dim strGroupName
 
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
        Case "Office"
            objNetwork.MapNetworkDrive "P:", "\\fs1\quality"
        Case "ManagersTest"
           objNetwork.MapNetworkDrive "R:", "\\fs1\managers"
 End Select
 
Next
 
If (LCase(objUser.SamAccountName) = "kensmith") Then 
objNetwork.MapNetworkDrive "S:", "\\fs1\managers"
 
End If

Open in new window

0
chineduke
Asked:
chineduke
  • 7
  • 6
1 Solution
 
TakedaTCommented:
The error means exactly that.  If something is already using a drive letter that you are trying to map something to, it will produce that error.  You can have the script look to see if the drive exists before it attempts to map.
0
 
chinedukeAuthor Commented:
Thanks Takeda for ur response.I already ran that check(though not in the script) and drive does not exist.Is it possible you could add that line to my script please,so i'll avoid making any errors.I also have thot of adding the RemoveNetworkDrive function just in case.But that did not seem to work.I'm thinking mabbe i added it on the wrong line of the code.
Thanks again for ur response.
0
 
TakedaTCommented:
Give this a go.  You may also have some hardware based mapping that may cause that error.
Option Explicit
Dim objSysInfo, objNetwork, strUserPath, objUser, strGroup, strGroupPath, objGroup, strGroupName
 
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
Set objNetDrives = objNetwork.EnumNetworkDrives
For Each strGroup In objUser.MemberOf
    strGroupPath = "LDAP://" & strGroup
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN
 
Select Case strGroupName
	Case "Office"      	
		CheckDrives "P:","\\fs1\quality"
	Case "ManagersTest"
		CheckDrives "R:","\\fs1\managers"
End Select
Next
 
If (LCase(objUser.SamAccountName) = "kensmith") Then 
	CheckDrives "S:","\\fs1\managers"
End If
Function CheckDrives(drive,path)
	Dim i, objNetDrives
	Set objNetDrives = objNetwork.EnumNetworkDrives
	CheckDrives = False
	For i = 0 to objNetDrives.Count - 1 Step 2
		If objNetDrives.Item(i) = drive and objNetDrives.Item(i+1) = path then
			CheckDrives = True
		Elseif objNetDrives.Item(i) = drive and objNetDrives.Item(i+1) <> path then
			objNetwork.RemoveNetworkDrive drive,True,True
			objNetwork.MapNetworkDrive drive,path
			CheckDrives = True
		End If
	Next
	If CheckDrives = False then objNetwork.MapNetworkDrive drive,path	
End Function

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chinedukeAuthor Commented:
Thanks again Takeda.Really appreciate. Your code seems very elaborate and i'm trying to adopt it.This might sound dumb, i'm not so clear how to handle the 'drive' and 'path' variables to include the drives and paths im working with.
I used the On Error Resume Next line in my original code and the error stopped popping up and the drives map correctly, but i want to adopt your code because down the line, thats what i believe i will very well need.Thanks again.
0
 
TakedaTCommented:
Basically, whenever you call the function from above, you pass your drive and path to the function.  So instead of just using the mapnetworkdrive method with the same drive and path, you pass the same drive and path to a function that first checks to see it its already mapped before attempting to map it.  the "drive" and "path" variables could have been named whatever I wanted as long as the variable name is consistend throughout the function.  

Anytime you would use the mapnetworkdrive method you would use this:
CheckDrives "P:","\\fs1\quality"
where CheckDrives is the function and the P: is the drive and \\fs1\quality is the path.

The function first checks if P: is already mapped.  If it is, then it checks what path it is mapped to.  If the path is the same as what you are trying to map, then the function just ends.  If the drive is mapped already, but has a different path, then it disconnects it and tries to map it to the path you want.
If the function doesnt find any mapping for the drive letter, then it just tries to map it.

Here is the msdn reference for the wshnetwork object.  Hopefully it can explain what you are looking for.

http://msdn.microsoft.com/en-us/library/907chf30(VS.85).aspx

0
 
chinedukeAuthor Commented:
Thanks for the explanation.I wanted to clarify that for each 'Case', the specified drive and paths would equate the drive and path values passed in ur checkdrive method.I deployed the script but i did not get any drive mappings, no errors either.i'm looking at it to determine whats missing.You got any ideas?
0
 
TakedaTCommented:
Did you take out the "on error resume next" ?  It may just be a stupid mistake on my part as I dont have the environment to test it.  Especially with the "option explicit" part.
0
 
chinedukeAuthor Commented:
Yep, that was the first thing i checked for in ur code.
0
 
TakedaTCommented:
I may have found the problem.  Try it again.  If it doesnt work, try it without the "option explicit" and also without the "on error resume next".  If it still doesnt work, let me know and tell me any errors, but I wont get to it until tomorrow as I have to leave now.  
Option Explicit
Dim objSysInfo, objNetwork, strUserPath, objUser, strGroup, strGroupPath, objGroup, strGroupName
 
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
        Case "Office"           
                CheckDrives "P:","\\fs1\quality"
        Case "ManagersTest"
                CheckDrives "R:","\\fs1\managers"
End Select
Next
 
If (LCase(objUser.SamAccountName) = "kensmith") Then 
        CheckDrives "S:","\\fs1\managers"
End If
Function CheckDrives(drive,path)
        Dim i, objNetDrives
        Set objNetDrives = objNetwork.EnumNetworkDrives
        CheckDrives = False
        For i = 0 to objNetDrives.Count - 1 Step 2
                If objNetDrives.Item(i) = drive and objNetDrives.Item(i+1) = path then
                        CheckDrives = True
                Elseif objNetDrives.Item(i) = drive and objNetDrives.Item(i+1) <> path then
                        objNetwork.RemoveNetworkDrive drive,True,True
                        objNetwork.MapNetworkDrive drive,path
                        CheckDrives = True
                End If
        Next
        If CheckDrives = False then objNetwork.MapNetworkDrive drive,path       
End Function

Open in new window

0
 
chinedukeAuthor Commented:
Thanks Takeda.I'll run the code first thing in the morning and update you on the status.
0
 
chinedukeAuthor Commented:
U Be Da Man Takeda. The freakn Script is on a roll. Thnx man. Full Points awarded. I'll buy you a beer anytime you swing by illinois.....lolol. Thanks again.
0
 
TakedaTCommented:
No problem, glad to help.  But you didnt award points and are closing the question. :(
0
 
chinedukeAuthor Commented:
Points Awarded.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now