咨询Windows命令行中添加本地打印机端口的对应命令(附PowerShell示例)
Hey there! I get you—you're using PowerShell's Add-PrinterPort -Name "NameYourLocalPort:" to set up a local printer port, and you need the equivalent command for regular Windows Command Prompt (cmd). Let's break this down because cmd doesn't have a direct 1:1 command like PowerShell does, but we can still get it done with a reliable built-in tool.
The Cmd Solution: Using rundll32 printui.dll,PrintUIEntry
Cmd relies on the PrintUIEntry utility (invoked via rundll32) to handle printer and port management tasks. Here's the exact command to create your local port:
rundll32 printui.dll,PrintUIEntry /if /b "TempLocalPrinter" /f "%windir%\inf\ntprint.inf" /r "NameYourLocalPort:" /m "Generic / Text Only"
Let's break down each parameter:
/if: Instructs the tool to install a printer using an INF file (required to attach the port to a printer object temporarily)/b "TempLocalPrinter": A temporary printer name—you can use any name here (this is just a placeholder to associate the port with; you can delete it later if you only need the port)/f "%windir%\inf\ntprint.inf": Path to Windows' standard printer INF file (no need to modify this path)/r "NameYourLocalPort:": This is your target local port name—keep the colon at the end, just like you did in your PowerShell command/m "Generic / Text Only": A generic printer driver that works for creating the port without needing a specific printer model
Optional: Remove the Temporary Printer (If You Only Need the Port)
If you don't want the placeholder printer cluttering up your system, you can delete it right after creating the port with this cmd command:
rundll32 printui.dll,PrintUIEntry /dn /n "TempLocalPrinter"
The local port you created will remain active even after removing the printer.
This is the standard method for creating local printer ports in cmd, since there's no dedicated standalone command equivalent to PowerShell's Add-PrinterPort.
内容的提问来源于stack exchange,提问作者Tsal Giorgos

