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.

5 Answers 5


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

  • 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. Mar 1, 2016 at 21:21
  • 2
    Thumbs down for broken link Feb 6, 2018 at 23:21

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

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()}"

you mean like:

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


  • this works with ip addresses, not just URI's
  • you can loop back a local printer NET USE LPT1: \\
  • He said TCP/IP printer port. You have provided instructions for adding an SMB printer.
    – eleven81
    Oct 27, 2009 at 21:10
  • 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
    Oct 27, 2009 at 21:23
  • that will accept '\\' as an argument. LocalAddPortUI will force a dialog. Oct 27, 2009 at 21:29

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...


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 -h

::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 "" /m "EXACT NAME OF DRIVER AS WRITTEN IN .inf FILE"

Make sure you change the 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.