|
-
December 17th, 2008, 02:04 PM
#1
Registered User
vbscript to add printer
Let me be the first to say that I barely know vbscript, so I searched the magical interwebs and found the following script to add an IP printer to a local machine.
Code:
PrnName = "COLOR_PRN"
PrnLocation = "PRN Room"
PrnComment = "HP Color LaserJet 3600"
PrnDrv = "HP Color LaserJet 3600"
DrvPath = "HP 3600n"
'Wsh.echo DrvPath
InfPath = DrvPath & "\hpc3600e.inf"
'Wsh.echo InfPath
PortIP = "192.168.100.100"
PortName = "IP_" & PortIP
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = PortName
objNewPort.Protocol = 1
objNewPort.HostAddress = PortIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
wsh.echo "port created"
''''''''''''''''''''''''''
' install printer driver
''''''''''''''''''''''''''
' If the driver is not signed, one cannot use WMI scripting
' to install the driver.
' Make sure the cat file for the package is copied to the same
' location as the driver
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = PrnDrv
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriver.DriverPath = DrvPath
objDriver.Infname = InfPath
intResult = objDriver.AddPrinterDriver(objDriver)
wsh.echo "driver installed"
''''''''''''''''''''''''''
' Add local printer
''''''''''''''''''''''''''
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = PrnDrv
objPrinter.PortName = PortName
objPrinter.DeviceID = PrnName
objPrinter.Location = PrnLocation
objPrinter.Comment = PrnComment
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.Put_
wsh.echo "printer added"
'optional:
''''''''''''''''''''''''''
' Stop & Start Printer Spooler
''''''''''''''''''''''''''
'Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'")
'iReturn = objSpoolerSvc.StopService()
'iReturn = objSpoolerSvc.StartService()
This script seems to work fine if there was a previously added IP printer installed, however if there have been no IP printers installed, then the script bombs out on the objPrinter.Put_ command within the Add local printer section complaining about a SWbemObjectEx: Generic failure
(80041001) error. Since this is kind of defeats the purpose of using a script for IP Printer installation, I figured I'd see if anyone here had any thoughts on why this would occur?
Similar Threads
-
By Yakuza389 in forum Digital Imaging
Replies: 4
Last Post: January 31st, 2006, 04:25 PM
-
By TEHendricks in forum Windows 95/98/98SE/ME
Replies: 4
Last Post: August 21st, 2005, 02:32 PM
-
By suruda1 in forum Windows XP
Replies: 7
Last Post: February 26th, 2004, 10:14 PM
-
By RIOT in forum Digital Imaging
Replies: 3
Last Post: September 25th, 2001, 05:11 PM
-
By Zealing in forum Tech-To-Tech
Replies: 0
Last Post: September 10th, 2000, 08:18 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks