Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS Script Error The local device name is already in use

Posted on 2007-04-11
14
Medium Priority
?
2,881 Views
Last Modified: 2008-03-06
I am working with a logon script that someone else wrote and wandering if anyone could help straighten it out.
Scripting error
Line: 22
Char: 1
Error: the local device name is already in use.
Code: 80070055
Source: WSHNetwork.MapNetworkDrive

Here is the script:
' Maps "S" to Shared
'
'
' Author:  
' Version 1.1- March 19, 2007
' ----------------------------------------'
'

Option Explicit
Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName
Dim WshNetwork, oDrives, i
Dim bUpdateProfile
bUpdateProfile = "True"


'-- Setting objects --
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
bUpdateProfile

DriveMapper"S:","\\server1\shared"

Sub DriveMapper(Drive, Share)
For i = 0 to oDrives.Count -1 Step 2
if LCase(Drive) = LCase(oDrives.Item(i)) then
if not LCase(Share) = LCase(oDrives.Item(i+1)) then
WshNetwork.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
WshNetwork.MapNetworkDrive Drive, Share
End Sub

'Line 37



' Section to map the network drive
Set WshNetwork = CreateObject("WScript.Network")
'

' Section which actually (re)names the Mapped Drive
'Set objShell = CreateObject("Shell.Application")
'objShell.NameSpace(strDriveLetter).Self.Name = strNewName


'Wscript.Echo "Check : "& strDriveLetter & " for " & strNewName
'WScript.Quit

' End of script.
0
Comment
Question by:summititsolutions
[X]
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
  • 8
  • 6
14 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18892876
Change this line:

DriveMapper "s:","\\server1\shared"
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 18892943
Here's a shorter version...

Dim objNet:Set objNet=CreateObject("WScript.Network")

bUpdateProfile = "True"
Set oDrives = WshNetwork.EnumNetworkDrives
strDrive="s:"
strShare="\\server1\shared"

For i = 0 to oDrives.Count -1 Step 2
if strDrive = LCase(oDrives.Item(i)) then
  if not strShare = LCase(oDrives.Item(i+1)) then objNet.RemoveNetworkDrive strDrive, true, true
End if
Next
objNet.MapNetworkDrive Drive, Share

Set objNet=Nothing
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18897200
On the first respnse what would i change that line to?  And on the second response,, well here is what we are trying to accomplish.  We want the login script to run without error whether we are plugged into our netowrk here or if we login to our tablets from say at home it will still map the drive and get no errors and be persistent, will the shorter version do this?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18897216
If you're not on your network, how will you connect to the server?  VPN?

It should work either place if so..
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18897250
Sorry, yes would be vpn.  And looks like the shorter version is going to work, thanx for the help.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18897257
Glad I could assist you. :^)
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18904853
Not sure if I should put this here or open another but after looking at this a little farther i got the following error once running it.
Windows Script Host
Line: 11
char: 1
error: Object required: 'WshNetwork'
code: 800A01A8
Source: Microsoft VBscript Runtime error

Am I missing something here?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18904861
My mistake...I didn't update all references..this should work...


Dim objNet:Set objNet=CreateObject("WScript.Network")

bUpdateProfile = "True"
Set oDrives = objNet.EnumNetworkDrives
strDrive="s:"
strShare="\\server1\shared"

For i = 0 to oDrives.Count -1 Step 2
if strDrive = LCase(oDrives.Item(i)) then
  if not strShare = LCase(oDrives.Item(i+1)) then objNet.RemoveNetworkDrive strDrive, true, true
End if
Next
objNet.MapNetworkDrive Drive, Share

Set objNet=Nothing
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18905520
Should I just open another question for this, not sure if I should keep posting under this one since i already closed it:)

Now I get the following -

windows script host
line 13:
char: 1
error: the network name cannot be found
code: 80070043
source: WSHNetwork.MapNetworkDrive
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18905555
Where are you using WshNetwork?
Your error still points to that reference...WSHNetwork.MapNetworkDrive

It doesn't matter what you call it (I just use objNet for mine) - but it has to be consistent...
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18909669
I copied your short version and pasted it into a blank vbs file and called it default.vbs, when I run it I get that error.  Should I have put it into my original script somewhere?  Or is it supposed to run by itself?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18910168
OKay, I guess I misread the error - you did update this line, didn't you?

strShare="\\server1\shared"
'it should read the exact server path to the share...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18910173
I'm on the road for a bit, so if you get stuck, you may want to open a new Q.
Otherwise, I'll be checking this again next week.
0
 
LVL 1

Author Comment

by:summititsolutions
ID: 18926571
Hello, yes that is the correct path \\server1\shared.  Any other ideas?  I am going to go ahead and open another Q on this, so you can continue helping with it if you lik on the new one.  Thanx, so far.

Dim objNet:Set objNet=CreateObject("WScript.Network")
bUpdateProfile = "True"
Set oDrives = objNet.EnumNetworkDrives
strDrive="s:"
strShare="\\server1\shared"
For i = 0 to oDrives.Count -1 Step 2
if strDrive = LCase(oDrives.Item(i)) then
  if not strShare = LCase(oDrives.Item(i+1)) then objNet.RemoveNetworkDrive strDrive, true, true
End if
Next
objNet.MapNetworkDrive Drive, Share
Set objNet=Nothing
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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