Windows – Command for adding new printer port type using inf files

portprinterwindows-server-2008-r2

Is there any batch or powershell command to add new printer port type using inf files.

I am able to see only below commands for adding TCP-IP and LPR ports and not port type.

rundll32 – Install printers using inf files.

Prnport.vbs – Creates, deletes, and lists standard TCP/IP printer ports, in addition to displaying and changing port configuration.

Add Add-PrinterPort powershell command which create a local printer port, a printer port using TCP, and LPR printer ports.

Any pointers will be helpful.

Best Answer

Print monitors (aka Ports) are installed just like every other driver.

You can use the "Install" verb which is available on the right click menu. From script, you can access this via the Shell.Application COM Object.

# Powershell
(New-Object -Com 'Shell.Application').ShellExecute('file.inf', '', '', 'Install')

# VBS
Set Shell = CreateObject("Shell.Application")
Shell.ShellExecute "file.inf", "", "", "Install"

On Windows 8.1, that maps to the following command, but I don't believe this is documented anywhere:

%SystemRoot%\System32\InfDefaultInstall.exe "file.inf"

On older systems (before Vista), you can also use the Windows API to install the INF via the InstallHinfSection function called via RunDll:

%SystemRoot%\System32\rundll32.exe SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 file.inf

You can also install a print monitor directly via the AddMonitor function, which you can call from Powershell.