Is it possible to add a default printer by IP rather than name of a printer on a print server? Thanks --Nicholas
I don't have an answer and as it always seems to be the case, the answer likely depends on the unmentioned details. First, you are asking about creating a WinBatch script to perform this task? If so then are you referring to a printer connected to a server or a printer connected directly to the network?
That said, WinBatch does have a Printer Extender, IPGrabber, and Network Extender that one or more of which could potentially be used in some fashion to create a script that accomplishes your task. You might want to peruse the documentation in the Consolidated WIL Help file to get some ideas. If you do find something useful please share it as it may be useful to someone else.
Hi, Yes, I'm looking to do this with winbatch. I want to connect directly to the network card of the printer. We're doing this because in Windows Server 2016 you can no longer have clustered print servers and we don't want a single point of failure in a single print server.
The printui.dll is still around in Windows 10 so you might find some useful functionality in it.
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Printing~Information+PRINTUI~Docs.txt (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Printing~Information+PRINTUI~Docs.txt)
Haven't tried it but here is WMI example written in VB. It should convert it to WinBatch with little effort:
https://gallery.technet.microsoft.com/scriptcenter/41a4c996-b7f7-4d58-808d-2acac20ddbf7 (https://gallery.technet.microsoft.com/scriptcenter/41a4c996-b7f7-4d58-808d-2acac20ddbf7)
The lengthy documentation fro the WMI Win32_Printer class:
https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-printer (https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-printer)
This works for me:
;-Add IP port
objWMIService = GetObject("winmgmts:")
objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
; Use IP of Printer or Machine sharing printer
objNewPort.Name = "IP_192.168.1.39"
objNewPort.Protocol = 1
objNewPort.HostAddress = "192.168.1.39"
; Enter Port number you would like to use
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = @FALSE
objNewPort.Put_
;Add printer
RunWait("rundll32.exe", 'printui.dll PrintUIEntry /if /b "Printer Name" /f "hpc4x50c.inf" /r "IP_192.168.1.39" /m "HP LaserJet 4240 PCL 6"')