Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Windows Script Host Error 80070055

Posted on 2009-05-06
13
1,511 Views
Last Modified: 2012-06-27
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
Comment
Question by:chineduke
  • 7
  • 6
13 Comments
 
LVL 10

Expert Comment

by:TakedaT
ID: 24317698
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
 

Author Comment

by:chineduke
ID: 24317919
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
 
LVL 10

Expert Comment

by:TakedaT
ID: 24318650
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:chineduke
ID: 24319644
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
 
LVL 10

Expert Comment

by:TakedaT
ID: 24320140
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
 

Author Comment

by:chineduke
ID: 24320302
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
 
LVL 10

Expert Comment

by:TakedaT
ID: 24320360
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
 

Author Comment

by:chineduke
ID: 24320445
Yep, that was the first thing i checked for in ur code.
0
 
LVL 10

Accepted Solution

by:
TakedaT earned 100 total points
ID: 24320730
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
 

Author Comment

by:chineduke
ID: 24322066
Thanks Takeda.I'll run the code first thing in the morning and update you on the status.
0
 

Author Comment

by:chineduke
ID: 24326088
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
 
LVL 10

Expert Comment

by:TakedaT
ID: 24327435
No problem, glad to help.  But you didnt award points and are closing the question. :(
0
 

Author Comment

by:chineduke
ID: 24327791
Points Awarded.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question