Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mapping a printer - "local device name already in use" error

Status
Not open for further replies.

sman26

Vendor
Jan 13, 2005
36
US
I am mapping an HP Laser Jet printer using vbs and group policies.

Here it is:
Set objNetwork = CreateObject("WScript.Network")
UserString = objNetwork.UserName

objNetwork.MapNetworkDrive "Z:" , "\\capitolserver\" & UserString,True
objNetwork.AddWindowsPrinterConnection "\\capitolserver\ISHPC3700"

When I log on the first time with the script works great with no errors so the script it correct. However the second time I log in I get the "The Local Device Name is Already In Use" and the error points to the vbs line referring to the printer mapping. I even tried to delete the printer and try again I get the error that it is in use. Do I need to write a DISCONNECT PRINTER script to take the printer off of the PC everytime so that the error won't occur. I have never seen anyone else have to do this but maybe people do?

Thanks for any help.
Shawn
 
well most people seem to put On Error Resume Next at the top of their scripts. Defensive programming is dead
 
MrMovie is correct. I don't know if it is the best soluktion, but here is an idea. Put an On Error Resume Next just before the line that errors. There will be a specific error number that is relevant to the mapping already existing. I don't know what it is but you can determine it in your code using Err.Number. after the line that maps the drive, check to make sure that Err.Number equals 0 or the number for a pre-existing mapping. If it does, then everything is hunky dory. If it does not then you have some real error that you need to deal with. After you have checked the error number, then put in the line On Error Goto 0.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top