Setting up TCP/IP Printer ports

Installing printers using standaard TCP/IP ports is the Microsoft recommended way to install printers and connect to shared printers. Unfortunately there does not same to be a way to script this, contrary to the WSH Network Object methods to connect to and install shared printers or the command line tools RUNDLL32 PRINTUI.DLL that can be used to < href="printers_local.htm">instal printer drivers and set up local printers.

If all else fails, mess with the registry. If no other scripting interfaces are available, we can always use a script to import some registry keys into the registry of the target machine to configure it the way we want it. That is the approach we will use to setup standaard TCP/IP printer ports.

This is just a preliminary exploration, and not all of this has been tested. Try at your own risk

The registry keys

The registry key for a TCP IP printer port looks like this :

	Windows Registry Editor Version 5.00

	[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports]
	;all defaults : RAW, port 9100
	[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_1.92.1.2]
	"SNMP Community"="public"
	"SNMP Enabled"=dword:00000000
	"SNMP Index"=dword:00000001
	;customized: LPR, LPR Queue Name, port 515
	[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.123]
	"SNMP Community"="public"
	"SNMP Enabled"=dword:00000000
	"SNMP Index"=dword:00000001
	"Double Spool"=dword:00000000

Assuming we stick with the defaults (RAW protocol, port 9100) the only variable is the printers IP address, which is used as an identifier for the registry key itself, and as a value/data in the key ("IPAddress"=""). so it should be possible, given a list of valid IP addresses, to automate the creation of registry keys.

There are a number of ways to script registry editing (through visual basic, kix, ...) but I still like good old batch files - especially when they read from or write to plain text files that can be easily modified should the need occur. So here we go : batch file registry editing ...


For input, we use a simple list of IP adresses


batch to create standard TCP/IP Ports for Printers

We simply write (echo) all relevant text to a .reg file, using a variable to hold the relevant IP address. Then we import the resulting .reg file into the registry. The .reg file can then be deleted, or kept for future reference.

		echo. > tcpipports.reg

		REM reg file header and parent key

		ECHO Windows Registry Editor Version 5.00
		ECHO [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports]
		ECHO "StatusUpdateInterval"=dword:0000000a
		ECHO "StatusUpdateEnabled"=dword:00000001

		) >> tcpipports.reg

		REM LOOP IP addresses and create keys

		For /F %%p in (tcpipports.txt) do

		ECHO ;port %%p
		ECHO [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_%%p]
		ECHO "Protocol"=dword:00000001
		ECHO "Version"=dword:00000001
		ECHO "HostName"=""
		ECHO "IPAddress"="%%p"
		ECHO "HWAddress"=""
		ECHO "PortNumber"=dword:0000238c
		ECHO "SNMP Community"="public"
		ECHO "SNMP Enabled"=dword:00000000
		ECHO "SNMP Index"=dword:00000001
		)  >> tcpipports.reg

		REM silently import the keys into the registry
		REGEDIT /S tcpipports.reg

		REM delete the reg file (in this case, consider using %temp%\tcpipports.reg )
		REM DEL tcpipports.reg


Obviously, we could manage multiple variables as well, with FOR /F "tokens ..." , and a corresponding list with multiple entries on each line (e.g. IPaddress Hostname ProtocolNr LPRQueue ... ). In that case, we might use conditional statements such as
IF %%y="00000002" (i.e. protocolnr 2 for LPR) ECHO "Queue"="%%z" in the description of the registry key.

And then ...

These printer ports can be used to print to remote, network-attached printers, provided you setup local printers using these tcpip ports. Of course, we will want to script installing printer drivers and local printers ...

New ! Improved !

In stead of importing registry keys, you can - on Windows 2003 Server and Windows XP - use prnport.vbs as a command to create TCPIP Printer ports. Refer to "Scripts to configure printers on Windows 2003 and Windows XP.


and take it frome there ...

Koen Noens
September 2005