To create a printer port using the command line you can use a microsoft utility found in the c:\Windows\System32 folder on Windows XP/2003 systems called prnport.vbs.
Using this VBScript makes it easy to add multiple printer ports for a new system or to migrate to a new port range for an existing server.
Open up a command prompt and cd to c:\windows\system32 then type the below command:
cscript prnport.vbs -a -r IP_10.0.0.254 -h 10.0.0.254 -o raw -n 9100 -me
This will a Raw IP printer port with the Address 10.0.0.254 with the port number 9100, it will also enable SNMP.
If you putting the above command within a DOS FOR loop you can create a tonne of ports in a few seconds. An Example is below:
for %i in (254,253,252,251,249,248,247,245,244,243,242,241) do cscript prnport.vbs -a -r IP_10.0.0.%i -h 10.0.0.%i -o raw -n 9100 -me
This will create the ports 10.0.0.241 through to 10.0.0.254
More info on this command using the help found in the VBScript file itself.:
C:\WINDOWS\system32>cscript.exe prnport.vbs /?
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Usage: prnport [-adlgt?] [-r port][-s server][-u user name][-w password]
[-o raw|lpr][-h host address][-q queue][-n number]
[-me | -md ][-i SNMP index][-y community][-2e | -2d]
Arguments:
-a – add a port
-d – delete the specified port
-g – get configuration for a TCP port
-h – IP address of the device
-i – SNMP index, if SNMP is enabled
-l – list all TCP ports
-m – SNMP type. [e] enable, [d] disable
-n – port number, applies to TCP RAW ports
-o – port type, raw or lpr
-q – queue name, applies to TCP LPR ports
-r – port name
-s – server name
-t – set configuration for a TCP port
-u – user name
-w – password
-y – community name, if SNMP is enabled
-2 – double spool, applies to TCP LPR ports. [e] enable, [d] disable
-? – display command usage
Examples:
prnport -l -s server
prnport -d -s server -r IP_1.2.3.4
prnport -a -s server -r IP_1.2.3.4 -h 1.2.3.4 -o raw -n 9100
prnport -t -s server -r IP_1.2.3.4 -me -y public -i 1 -n 9100
prnport -g -s server -r IP_1.2.3.4
prnport -a -r IP_1.2.3.4 -h 1.2.3.4
Remark:
The last example will try to get the device settings at the specified IP address.
If a device is detected, then a TCP port is added with the preferred settings for that device.