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