SForshaw
05-25-2004, 01:30 PM
Hi All:
First all, I am new to VB scripting and have have only been creating scripts fro about 2 weeks now.
I have created a script that will create an standard TCP/IP Printer port, install a print driver and then associate the driver and the port, thus creating a printer on the system. Operating system for all systems is XP Pro in an AD environment.
See code below:
'******************************************
' Installs a TCP/IP printer on a computer *
'******************************************
' Install Printer Port
set oWshShell = createobject("wscript.shell")
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
' Adding IP for Printer 1
objNewPort.Name = "x.x.x.x" ' (IP Adress of Printer)
objNewPort.Protocol = 2
objNewPort.HostAddress = "x.x.x.x" ' (Ip Address of Printer)
objNewPort.PortNumber = "525"
objNewPort.SNMPEnabled = True
objNewPort.Put_
oWshShell.popup "LPR port added !!"
' Install Print Driver
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "Printer name"
objDriver.SupportedPlatform = "W32x86"
objDriver.Version = "3"
objDriver.FilePath = "U:\Print Drivers"
objDriver.InfName = "U:\Print Drivers\printer.INF"
intResult = objDriver.AddPrinterDriver(objDriver)
WScript.Echo intResult
' Create Printer on system
dim oPrinter
set oPrinter = CreateObject("Printer.Printer.1")
' Name of the printer as it appears in the Printers folder
oPrinter.PrinterName = "Printer Name"
' Name that is referenced in printer-definition file (ex. nprint.inf)
oPrinter.DriverName = "Printer name"
' Specify a port name. Can also point to LPT or COM port.
oPrinter.PortName = "x.x.x.x"
oMaster.PrinterAdd oPrinter
If Err <> 0 then
msgbox "There was an error creating the printer."
end if
******************************************
Problem is this. The port is created successfully. However, the print driver does not get installed. Also, the last section generates an error as well. Could somene look at this and let know where iam going wrong?
First all, I am new to VB scripting and have have only been creating scripts fro about 2 weeks now.
I have created a script that will create an standard TCP/IP Printer port, install a print driver and then associate the driver and the port, thus creating a printer on the system. Operating system for all systems is XP Pro in an AD environment.
See code below:
'******************************************
' Installs a TCP/IP printer on a computer *
'******************************************
' Install Printer Port
set oWshShell = createobject("wscript.shell")
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
' Adding IP for Printer 1
objNewPort.Name = "x.x.x.x" ' (IP Adress of Printer)
objNewPort.Protocol = 2
objNewPort.HostAddress = "x.x.x.x" ' (Ip Address of Printer)
objNewPort.PortNumber = "525"
objNewPort.SNMPEnabled = True
objNewPort.Put_
oWshShell.popup "LPR port added !!"
' Install Print Driver
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "Printer name"
objDriver.SupportedPlatform = "W32x86"
objDriver.Version = "3"
objDriver.FilePath = "U:\Print Drivers"
objDriver.InfName = "U:\Print Drivers\printer.INF"
intResult = objDriver.AddPrinterDriver(objDriver)
WScript.Echo intResult
' Create Printer on system
dim oPrinter
set oPrinter = CreateObject("Printer.Printer.1")
' Name of the printer as it appears in the Printers folder
oPrinter.PrinterName = "Printer Name"
' Name that is referenced in printer-definition file (ex. nprint.inf)
oPrinter.DriverName = "Printer name"
' Specify a port name. Can also point to LPT or COM port.
oPrinter.PortName = "x.x.x.x"
oMaster.PrinterAdd oPrinter
If Err <> 0 then
msgbox "There was an error creating the printer."
end if
******************************************
Problem is this. The port is created successfully. However, the print driver does not get installed. Also, the last section generates an error as well. Could somene look at this and let know where iam going wrong?