How do I add a standard TCP/IP printer port from a command line?

8

5

Is there a way to use Rundll32.exe tcpmonui.dll,LocalAddPortUI from a command line to add a standard TCP/IP port for a printer?

Or any other way to add a standard TCP/IP printer port from a command line.

Adam L

Posted 2009-10-27T20:56:34.530

Reputation: 183

Answers

1

Acording to this page you can use the prnport command in XP.

MALeamy

Posted 2009-10-27T20:56:34.530

Reputation: 42

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

– Canadian Luke – 2016-03-01T21:21:18.790

2Thumbs down for broken link – Grimtech – 2018-02-06T23:21:18.023

13

Just so that others can find this here's the exact command (from cmd.exe) that I run to programmatically add a network printer under Windows 7 (this seems to be somewhat rare even after a lot of googling):

cscript c:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs ^
-a -r IP_10.0.0.100 -h 10.0.0.100

rundll32 printui.dll,PrintUIEntry /if /b "printer" /f %windir%\inf\prnhp002.inf^
/r "IP_10.0.0.100" /m "HP LaserJet 4200/4300 PCL6" /Z

(if you didn't know, as I didn't, ^ is the line continuation character in cmd.exe). You'll probably have to use a different inf file than the one listed above. I grep through all files in C:\Windows\inf looking for the exact text of my printer driver (HP LaserJet 4200/4300 PCL6") to discover the one that I need.

Another useful trick is to run a PowerShell one-liner to clear out any old printers that may exist (if it isn't obvious, this will delete all printers that you currently have installed):

powershell -command "foreach ($p in Get-WmiObject Win32_Printer) {$p.Delete()}"

Chris

Posted 2009-10-27T20:56:34.530

Reputation: 296

Here's the MSDN reference for the prnport.vbs script https://technet.microsoft.com/en-us/library/cc754352.aspx

– chris84948 – 2017-08-01T13:56:44.093

2

you mean like:

NET USE [local port to bind to ie LPT1] \\ComputerName\printer_share /PERSISTENT:YES

note:

  • this works with ip addresses, not just URI's
  • you can loop back a local printer NET USE LPT1: \\127.0.0.1:9100

Greg Buehler

Posted 2009-10-27T20:56:34.530

Reputation: 1 150

He said TCP/IP printer port. You have provided instructions for adding an SMB printer. – eleven81 – 2009-10-27T21:10:56.750

I think he needs to address it by IP, not server share. In my brief googling I could not find a way to do it unless the TCP/IP port had already been created locally. – djhowell – 2009-10-27T21:23:48.127

that will accept '\172.168.1.10' as an argument. LocalAddPortUI will force a dialog. – Greg Buehler – 2009-10-27T21:29:43.997

0

This thread is Necro'd but here is how I get printer installs done:

This is the script I use to install copiers and printers when we do bare metal reinstall of windows.

::Creating a Printer Port
cd c:\windows\system32\printing_admin_scripts\en-us\
Cscript Prnport.vbs -a -r 000.000.000.000 -h 000.000.000.000

::Install Printer Driver
rundll32 printui.dll,PrintUIEntry /ia /m "EXACT NAME OF DRIVER AS WRITTEN IN .inf FILE" /f "\\server\file\.inf"

::Create Printer in System
rundll32 printui.dll,PrintUIEntry /if /b "PRINTER NAME GOES HERE" /f "\\server\file.inf" /r "000.000.000.000" /m "EXACT NAME OF DRIVER AS WRITTEN IN .inf FILE"

Make sure you change the 000.000.000.000 to what your printer's IP is. \server\file\.inf is the location of the .inf file your for your driver.

This gets you from having nothing, to an installed, funtioning printer.

ThatoneITguy

Posted 2009-10-27T20:56:34.530

Reputation: 11

0

This page suggests that it is not possible unless the TCP/IP port already exists:

Note The following sample syntax works correctly as long as the standard TCP/IP ports are created:

rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r  "IP_157.57.50.98" /m "HP Laserjet 4000 Series PCL" /Z

If you do not enter the printer name correctly, or if you specify a printer that is not connected to the server, standard TCP/IP ports are not created, and you may receive the following error message...

djhowell

Posted 2009-10-27T20:56:34.530

Reputation: 3 535