Solved

Windows Script Host Error 80070055

Posted on 2009-05-06
13
1,493 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
 

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
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.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now