Solved

Windows Script Host Error 80070055

Posted on 2009-05-06
13
1,503 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

773 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