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 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] "StatusUpdateInterval"=dword:0000000a "StatusUpdateEnabled"=dword:00000001 ;all defaults : RAW, port 9100 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_18.104.22.168] "Protocol"=dword:00000001 "Version"=dword:00000001 "HostName"="" "IPAddress"="22.214.171.124" "HWAddress"="" "PortNumber"=dword:0000238c "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] "Protocol"=dword:00000002 "Version"=dword:00000001 "HostName"="" "IPAddress"="192.168.1.123" "HWAddress"="" "PortNumber"=dword:00000203 "SNMP Community"="public" "SNMP Enabled"=dword:00000000 "SNMP Index"=dword:00000001 "Queue"="this_is_a_user_defined_lpr_ue" "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"="192.168.1.123"). 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
192.168.120.201 192.168.120.202 192.168.120.203 192.168.120.204 192.168.120.2...
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. ECHO [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports] ECHO "StatusUpdateInterval"=dword:0000000a ECHO "StatusUpdateEnabled"=dword:00000001 ECHO. ECHO. ) >> tcpipports.reg REM LOOP IP addresses and create keys For /F %%p in (tcpipports.txt) do ( ECHO ;port %%p ECHO. 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 ECHO. ECHO. ) >> 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.
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 ...
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 ...