Posts tagged: print

Remove all Network Printers using VBScript

To delete a network printer using a login script you can use the following vb code. Just copy and paste the text into a new file called DeleteNetworkPrinters.vbs and call it from within your login script.

This will not delete any local printers installed to the machine. This is really useful to put in before you start mapping network printers during user logon.

‘————————————————————————-

‘– Removes all network printers but not any local printers–

‘————————————————————————-

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)

Set colInstalledPrinters =  objWMIService.ExecQuery _
(“Select * from Win32_Printer Where Network = TRUE”)

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

‘————————————————————————-

I’ve tested this code on Windows XP and Windows 7 and it works fine. I’m going to assume this is working on Windows Vista as well.

Share

Create a Printer Port from the Command Line using VB Script

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.

Share