Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

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

share|improve this answer
add comment

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()}"
share|improve this answer
add comment

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
share|improve this answer
    
He said TCP/IP printer port. You have provided instructions for adding an SMB printer. –  eleven81 Oct 27 '09 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 '09 at 21:23
    
that will accept '\\172.168.1.10' as an argument. LocalAddPortUI will force a dialog. –  Greg Buehler Oct 27 '09 at 21:29
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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