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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping printers based on AD sites...

Status
Not open for further replies.

TheJag

Technical User
Apr 11, 2006
3
I'm new to VBS so I'm just trying a simple script to map printers. I'm having issues with passing variables when the data in them has spaces. For instance if I do this:

oMaster.PrinterConnectionAdd "\\server\SHARP MX-2700N PCL6"

The printer gets added.

But if I do this where oPrinter.PrinterName is the variable:

oMaster.PrinterConnectionAdd oPrinter.PrinterName

I get Microsoft VBScript runtime error: Object required : ''

I've put """ and with & and still have problems. Here is my whole code, maybe I'm not passing the variable correctly?

option explicit
dim oMaster
dim PrinterName1
dim oPrinter
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
set oPrinter = CreateObject("Printer.Printer.1")
for each oPrinter in oMaster.Printers("\\sthomdc01")
wscript.echo "PrinterName : " & oPrinter.PrinterName
next
PrinterName1 = """&&oPrinter.PrinterName&&"""
wscript.echo PrinterName1
oMaster.PrinterConnectionAdd oPrinter.PrinterName

 
Sorry, but your code makes no sense for me as oPrinter is finally the last object in the oMaster.Printers("\\sthomdc01") collection.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You should be using the WScript.Network object to map printers on clients. The PrintMaster.PrintMaster object is only available if you register prnadmin.dll from the resource kit on every machine. That is why you are getting the "Object Required" error.

Code:
Dim oNetwork
Set oNetwork = CreateObject("WScript.Network")
oNetwork.AddPrinterConnection "\\servername\queuename"

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top