I have been experiencing the exact same issue.
Server:
Windows Server 2003 R2, SP1
Workstation:
Windows XP Professional, SP2
The script, which I will paste below, works fine on my XP machine. I
can create the port AND the printer on my XP workstation.
I have found that Win32_TCPIPPrinterPort *WILL* work on my server. The
port will get created just fine, but the printer will not on the
server.
I am BRAND NEW to VBScript, my experience is limited, and I am learning
as I go along.
I'd like to know if I have to abandon this script and use the RK as
recommended previously, or if I can "fix" this to work properly...
Here is my script:
Code:
--------------------
Dim Computer, DriverName, DriverInf, IPAddress, PrinterHostName, PortName
Dim WMI, NewPort, NewDriver, NewPrinter
Dim ArgObj, var1
Dim strComputer, objWMIService, objPrinter
Set ArgObj = WScript.Arguments
var1 = ArgObj(0)
Computer = "."
DriverName = "HP Universal Printing PCL 6"
PrinterHostName = var1 & ".fabrikam.loc"
IPAddress = PrinterHostName
' END CALLOUT A
WScript.Echo "PrinterHostName: " & PrinterHostName
PortName = PrinterHostName
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate" _
& ",(LoadDriver)}!//" & Computer & "/root/cimv2")
Set NewPort = WMI.Get("Win32_TCPIPPrinterPort").SpawnInstance_
NewPort.HostAddress = IPAddress
NewPort.Name = PortName
NewPort.Protocol = 1
NewPort.SNMPEnabled = 1
NewPort.SNMPCommunity = "public"
NewPort.Put_
WScript.Echo "Created printer port: " & PortName
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = DriverName
objPrinter.PortName = PortName
objPrinter.DeviceID = var1
objPrinter.Location = var1
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = var1
objPrinter.Default = True
objPrinter.Put_
WScript.Echo "Created printer: " & var1
WScript.Echo " Using Driver: " & DriverName
WScript.Echo " Shared As: " & var1
WScript.Echo " On Port: " & PortName
--------------------
--
greggplatinum
------------------------------------------------------------------------
greggplatinum's Profile:
http://forums.techarena.in/member.php?userid=27212
View this thread:
http://forums.techarena.in/showthread.php?t=92376
http://forums.techarena.in >> Stay informed about: Problem with script to add printers ports, need help.