Solved

Windows Script Host Error 80070055

Posted on 2009-05-06
13
1,483 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

19 Experts available now in Live!

Get 1:1 Help Now