PDA

View Full Version : Scripting help


arstacey
February 20th, 2008, 04:37 PM
I have this script that is supposed to add a local tcp/ip port, then add a network printer adn make it the default. It adds the port fine but I am getting this error on Line 90 Char 1 :

Error: The parameter is incorrect

Code: 80070057

Source: (null)



This is on the line that reads: oPrintMaster.PrinterAdd oPrinter
This line is the one that is actually supposed to add the printer I believe.



Can anyone tell me what I am doing wrong?



Thanks!





'************************************************* ************************************************** *************************************************
'Register the prnadmin.dll on client machine

Set WshShell = Wscript.CreateObject("Wscript.Shell")

WshShell.Run "regsvr32 /s \\192.168.1.80\distribution\printers\prnadmin.dll",1,TRUE

'************************************************* ************************************************** *************************************************

'The following code adds the TCP/IP Printing Port

dim oPort
dim oMaster
set oPort = CreateObject("Port.Port.1")
set oMaster = CreateObject("PrintMaster.PrintMaster.1")

'Indicate where to add the port. Double quotes ("" ) stand for the local computer, which is the default.
oPort.ServerName = ""

'The name of the port cannot be omitted.
oPort.PortName = "IP_192.168.33.10"

'The type of the port can be 1 (TCP RAW), 2 (TCP LPR), or 3 (standard local).
oPort.PortType = 1

'Mandatory for TCP ports. This is the address of the device to which the port connects.
oPort.HostAddress = "192.168.33.10"

'For TCP RAW ports. Default is 9100.
oPort.PortNumber = 9100

'Enable or disable SNMP.
oPort.SNMP = true

'If SNMP is enabled, 1 is the default for index.
oPort.SNMPDeviceIndex = 2

'If SNMP is enabled, "public" is the default community name.
oPort.CommunityName = "public"

'Applies to TCP LPR name, default is LPR
oPort.QueueName = "Queue"

'Byte counting or double spool applies to TCP LPR ports, is disabled by default.
oPort.DoubleSpool = false

'Try adding the port.
oMaster.PortAdd oPort
'Test for the status.
If Err <> 0 then

'An error occurred.
end if

'************************************************* ************************************************** *************************************************

'The following code adds the printer to the computer

dim oPrintMaster
dim oPrinter

'The following code creates the required PrintMaster and Printer objects.
set oPrintMaster = CreateObject("PrintMaster.PrintMaster.1")
set oPrinter = CreateObject("Printer.Printer.1")

'The following code specifies the name of the computer where the printer will be added. To specify the local
'computer, either use empty quotes (“”) for the computer name, or do not use the following line of code. If
'ServerName is not set, the local computer is used. Always precede the name of a remote computer
'with two backslashes (\\).
'oPrinter.ServerName = ""

'The following code assigns a name to the printer. The string is required and cannot be empty.
oPrinter.PrinterName = "Dell@303"

'The following code specifies the printer driver to use. The string is required and cannot be empty.
oPrinter.DriverName = "Dell Laser Printer 5100cn PCL6"

'The following code specifies the printer port to use. The string is required and cannot be empty.
oPrinter.PortName = "IP_192.168.33.10"

'The following code specifies the location of the printer driver. This setting is optional, because by default
'the drivers are picked up from the driver cache directory.
oPrinter.DriverPath = "\\192.168.1.80\distribution\printers\Dell5100or511 0"

'The following code specifies the location of the INF file. This setting is optional, because by default the INF
'file is picked up from the %windir%\inf\ntprint.inf directory.
oPrinter.InfFile = "\\192.168.1.80\distribution\printers\Dell5100or511 0\dlxcrzi.inf"

'The following code adds the printer.

oPrintMaster.PrinterAdd oPrinter

'The following code uses the Err object to determine whether the printer was added successfully.
if Err <> 0 then
'An error occurred
end if

'************************************************* ************************************************** *************************************************

'Set this printer as the default printer

dim oDefaultMaster

'The following code creates the required PrintMaster object.
set oDefaultMaster = CreateObject("PrintMaster.PrintMaster.1")

'The following code sets the default printer on the local computer.
oDefaultMaster.DefaultPrinter = "Dell@303"

'The following code uses the Err object to determine whether the default printer was updated successfully.
if Err <> 0 then
'An error occurred
end if