Category Archives: Batch Commands

Pubprn.vbs

The pubprn.vbs command can be used to publish a printer to the Active Directory Domain Services. Similar to prncnfg.vbs and prnmngr.vbs, the Pubprn.vbs command is a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. To use this command, at a command prompt, type cscript followed by the full path to the Pubprn.vbs file, or change directories to the appropriate folder.

Syntax (view syntax formatting guide):

Cscript Pubprn.vbs {<ServerName> | <UNCPrinterPath>} "LDAP://CN=<Container>,DC=<Container>"

Syntax Explanation

  • ServerName: Specifies the name of the Windows server that hosts the printer that you want to publish. If you do not specify a computer, the local computer is used.
  • UNCPrinterPath: The Universal Naming Convention (UNC) path to the shared printer that you want to publish.
  • “LDAP://CN=Container,DC=Container“: Specifies the path to the container in Active Directory Domain Services where you want to publish the printer.
  • /?: Displays help at the command prompt.

Explanation with Examples

To publish all printers on the \Server1 computer to the MyContainer container in the MyDomain.Company.Com domain:

cscript Ppubprn.vbs Server1 “LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com”

To publish the LaserPrinter1 printer on the \Server1 server to the MyContainer container in the MyDomain.Company.Com domain:

cscript Ppubprn.vbs \Server1LaserPrinter1 “LDAP://CN=MyContainer,DC=MyDomain,DC=Company,DC=Com”

 

Prnqctl.vbs

The Prnqctl.vbs command is used to print a test pages, pause or resume a printer, and clear the printer queue. Similar to the prncnfg.vbs, prndrvr.vbs, prnjobs.vbs, prnmngr.vbs and prnport.vbs commands, the Prnqctl.vbs command is a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. To use this command, at a command prompt, type Cscript followed by the full path to the Prnqctl.vbs file, or change directories to the appropriate folder.

Syntax (view syntax formatting guide):

Cscript Prnqctl {-z | -m | -e | -x | -?} [-s <ServerName>] [-p <PrinterName>] [-u <UserName>] [-w <Password>]

Syntax Explanation

  • -z: Pauses printing on the printer specified with the -p parameter.
  • -m: Resumes printing on the printer specified with the -p parameter.
  • -e: Prints a test page on the printer specified with the -p parameter.
  • -x: Cancels all print jobs on the printer specified with the -p parameter.
  • -s ServerName: Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -p PrinterName: Specifies the name of the printer that you want to manage. Required.
  • -u UserName -w Password: Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • /?: Displays help at the command prompt.

Explanation with Examples

To print a test page on the LaserPrinter1 printer shared by the \Server1 computer:

cscript Prnqctl -e -s Server1 -p LaserPrinter1

To pause printing on the LaserPrinter1 printer on the local computer:

cscript Prnqctl -z -p LaserPrinter1

To cancel all print jobs on the LaserPrinter1 printer on the local computer:

cscript Prnqctl -x -p LaserPrinter1

 

Prnport.vbs

The Prnport.vbs command is used to create, delete, and list standard TCP/IP printer ports, in addition to displaying and changing port configuration. Similar to the prncnfg.vbs, prndrvr.vbs, prnjobs.vbs and prnmngr.vbs, the Prnport.vbs command is a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. To use this command, at a command prompt, type cscript followed by the full path to the Prnport.vbs file, or change directories to the appropriate folder.

Syntax (view syntax formatting guide):

Cscript prnport {-a | -d | -l | -g | -t | -?} [-r <PortName>] [-s <ServerName>] [-u <UserName>] [-w <Password>] [-o {raw | lpr}] [-h <HostAddress>] [-q <QueueName>] [-n <PortNumber>] -m{e | d} [-i <SNMPIndex>] [-y <CommunityName>] -2{e | -d}

Syntax Explanation

  • -a: Creates a standard TCP/IP printer port.
  • -d: Deletes a standard TCP/IP printer port.
  • -l: Lists all standard TCP/IP printer ports on the computer specified with the -s parameter.
  • -g: Displays the configuration of a standard TCP/IP printer port.
  • -t: Configures the port settings for a standard TCP/IP printer port.
  • -r PortName: Specifies the port to which the printer is connected.
  • -s ServerName: Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -u UserName -w Password: Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • -o {raw | lpr}: Specifies which protocol the port uses: TCP raw or TCP LPR. If you use TCP raw, you can optionally specify the port number by using the -n parameter. The default port number is 9100.
  • -h HostAddress: Specifies (by IP address) the printer for which you want to configure the port.
  • -q QueueName: Specifies the queue name for a TCP raw port.
  • -n PortNumber: Specifies the port number for a TCP raw port. The default port number is 9100.
  • -m{e | d}: Specifies whether SNMP is enabled. The parameter e enables SNMP. The parameter d disables SNMP.
  • -i SNMPIndex: Specifies the SNMP index, if SNMP is enabled. For more information, see RFC 1759 at the RFC Editor Web site (http://go.microsoft.com/fwlink/?LinkId=569).
  • -y CommunityName: Specifies the SNMP community name, if SNMP is enabled.
  • -2{e | -d}: Specifies whether double spools (also known as respooling) are enabled for TCP LPR ports. Double spools are necessary because TCP LPR must include an accurate byte count in the control file that is sent to the printer, but the protocol cannot get the count from the local print provider. Therefore, when a file is spooled to a TCP LPR print queue, it is also spooled as a temporary file in the system32 directory. TCP LPR determines the size of the temporary file and sends the size to the server running LPD. The parameter e enables double spools. The parameter d disables double spools.
  • /?: Displays help at the command prompt.

Explanation with Examples

To display all standard TCP/IP printing ports on the server \Server1:

cscript Prnport.vbs -l -s Server1

To delete the standard TCP/IP printing port on the server \Server1 that connects to a network printer at 10.2.3.4:

cscript Prnport.vbs -d -s Server1 -r IP_10.2.3.4

To add a standard TCP/IP printing port on the server \Server1 that connects to a network printer at 10.2.3.4 and uses the TCP raw protocol on port 9100:

cscript Prnport.vbs -a -s Server1 -r IP_10.2.3.4 -h 10.2.3.4 -o raw -n 9100

To enable SNMP, specify the “public” community name and set the SNMP index to 1 on a network printer at 10.2.3.4 shared by the server \Server1:

cscript Prnport.vbs -t -s Server1 -r IP_10.2.3.4 -me -y public -i 1 -n 9100

To add a standard TCP/IP printing port on the local computer that connects to a network printer at 10.2.3.4 and automatically get the device settings from the printer:

cscript Prnport.vbs -a -r IP_10.2.3.4 -h 10.2.3.4

 

Prnmngr.vbs

The Prnmngr.vbs command is used to add, delete, and list printers or printer connections. The prnmngr.vbs command can also be used to set and display the default printer. Similar to the prncnfg.vbs, prndrvr.vbs and prnjobs.vbs commands, the prndrvr.vbs command is a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. To use this command, at a command prompt, type cscript followed by the full path to the Prnmngr.vbs file, or change directories to the appropriate folder

Syntax (view syntax formatting guide):

Cscript Prnmngr {-a | -d | -x | -g | -t | -l | -?}[c] [-s <ServerName>] [-p <PrinterName>] [-m <PrinterModel>] [-r <PortName>] [-u <UserName>] [-w <Password>]

Syntax Explanation

  • -a: Adds a local printer connection.
  • -d: Deletes a printer connection.
  • -x: Deletes all printers from the server specified with the -s parameter. If you do not specify a server, Windows deletes all printers on the local computer.
  • -g: Displays the default printer.
  • -t: Sets the default printer to the printer specified by the -p parameter.
  • -l: Lists all printers installed on the server specified by the -s parameter. If you do not specify a server, Windows lists the printers installed on the local computer.
  • c: Specifies that the parameter applies to printer connections. Can be used with the -a and -x parameters.
  • -s ServerName: Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -p PrinterName: Specifies the name of the printer that you want to manage.
  • -m DriverModelName: Specifies (by name) the driver you want to install. Drivers are often named for the model of printer they support. See the printer documentation for more information.
  • -r PortName: Specifies the port where the printer is connected. If this is a parallel or a serial port, use the ID of the port (for example, LPT1: or COM1:). If this is a TCP/IP port, use the port name that was specified when the port was added.
  • -u UserName -w Password: Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • /?: Displays help at the command prompt.

Explanation with Examples

To add a printer named ColorPrinter_2 that is connected to LPT1 on the local computer and requires a printer driver called Color Printer Driver1:

cscript Prnmngr.vbs -a -p ColorPrinter_2 -m “Color Printer Driver1″ -r lpt1:

To delete the printer named ColorPrinter_2 from the remote computer named HRServer:

cscript Prnmngr.vbs -d -s HRServer -p ColorPrinter_2

 

Prnjobs.vbs

The Prnjobs.vbs command is used to pause, resume, cancel and list the print jobs in a specified print queue. Similar to the prncnfg.vbs and prndrvr.vbs command, the prnjobs.vbs command is a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. To use the prnjobs.vbs command at the command prompts, type Cscript followed by the full path to the Prnjobs.vbs file, or change directories to the appropriate folder.

Syntax (view syntax formatting guide):

Cscript Prnjobs {-z | -m | -x | -l | -?} [-s <ServerName>]
[-p <PrinterName>] [-j <JobID>] [-u <UserName>] [-w <Password>]

Syntax Explanation

  • -z: Pauses the print job specified with the -j parameter.
  • -m: Resumes the print job specified with the -j parameter.
  • -x: Cancels the print job specified with the -j parameter.
  • -l: Lists all the print jobs in a print queue.
  • -s ServerName: Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -p PrinterName: Specifies the name of the printer that you want to manage. Required.
  • -j JobID: Specifies (by ID number) the print job you want to cancel.
  • -u UserName -w Password: Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • /?: Displays help at the command prompt.

Explanation with Examples

To pause a print job with a job ID of 27 sent to the remote computer named HRServer for printing on the printer named ColorPrinter, type:

Cscript Prnjobs.vbs -z -s HRServer -p ColorPrinter -j 27

To list all current print jobs in the queue for the local printer named ColorPrinter_2, type:

Cscript Prnjobs.vbs -l -p ColorPrinter_2

 

Prndrvr.vbs

The Prndrvr.vbs command is used to add, delete and list the installed printer drivers. Equivalent to prncnfg.vbs command, the prndrvr.vbs command is also a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts directory. The prpndrvr.vbs command is also used at the command prompt by typing; cscript followed by the full path to the Prndrvr.vbs file, or change directories to the appropriate folder.

  • If the information that you supply contains spaces, use quotation marks around the text (for example, “Computer Name”).

Syntax (view syntax formatting guide):

Cscript prndrvr {-a | -d | -l | -x | -?} [-m <model>] [-v {0|1|2|3}] [-e <environment>] [-s <ServerName>] [-u <UserName>] [-w <Password>] [-h <path>] [-i <inf file>]

Syntax Explanation

  • -a: Installs a driver.
  • -d: Deletes a driver.
  • -l: Lists all printer drivers installed on the server specified by the -s parameter. If you do not specify a server, Windows lists the printer drivers installed on the local computer.
  • -x: Deletes all printer drivers and additional printer drivers not in use by a logical printer on the server specified by the -s parameter. If you do not specify a server to remove from the list, Windows deletes all unused printer drivers on the local computer.
  • -m : Specifies (by name) the driver you want to install. Drivers are often named for the model of printer they support. See the printer documentation for more information.
  • -v {0 | 1 | 2 | 3}: Specifies the version of the driver you want to install. See the description of the “–e” parameter for information on which versions are available for which environment. If you do not specify a version, the version of the driver appropriate for the version of Windows running on the computer where you are installing the driver is installed.

Version 0 supports Windows 95, Windows 98, and Windows Millennium Edition.
Version 1 supports Windows NT 3.51.
Version 2 supports Windows NT 4.0.
Version 3 supports Windows Vista, Windows XP, Windows 2000, and the Windows Server 2003 operating systems. Note that this is the only printer driver version that Windows Vista supports.

  • -e : Specifies the environment for the driver you want to install. If you do not specify an environment, the environment of the computer where you are installing the driver is used. The supported environment parameters are:

“Windows NT x86″
“Windows x64″
“Windows IA64″

  • -s : Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -u -w : Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • -h: Specifies the path to the driver file. If you do not specify a path, the path to the location where Windows was installed is used.
  • -i : Specifies the complete path and file name for the driver you want to install. If you do not specify a file name, the script uses one of the inbox printer .inf files in the inf subdirectory of the Windows directory.

If the driver path is not specified, the script searches for driver files in the driver.cab file.

  • /?: Displays help at the command prompt.

Explanation with Examples

To list all drivers on the \PrintServer1 server:

cscript Prndrvr -l –s

To add a version 3 Windows x64 printer driver for the “Laser Printer Model 1″ model of printer using the C:tempLaserPrinter1.inf driver information file for a driver stored in the C:temp folder:

cscript Prndrvr -a -m “Laser Printer Model 1″ -v 3 -e “Windows x64″ -i c:tempLaserPrinter1.inf -h c:temp

To delete a version 3 Windows NT x86 printer driver for “Laser Printer Model 1″:

cscript Prndrvr -a -m “Laser Printer Model 1″ -v 3 -e “Windows NT x86″

Prncnfg.vbs

The Prncnfg.vbs command is used to configure and display information about a printer. The Prncnfg.vbs command is actually a Visual Basic script located in the %WINDIR%System32Printing_Admin_Scripts<language> directory. So in order to use this command correctly you must first type cscript followed by the full path to the Prncnfg.vbs file, or change directories to the appropriate folder. The Prncnfg.vbs command is a very usefull tool for managing and maintaining the printers attached to local and remote computers using VB scripts.

 

Syntax (view syntax formatting guide):

Cscript Prncnfg {-g | -t | -x | -?} [-S <ServerName>] [-P <PrinterName>] [-z <NewPrinterName>] [-u <UserName>] [-w <Password>] [-r <PortName>] [-l <Location>] [-h <ShareName>] [-m <Comment>] [-f <SeparatorFileName>] [-y <Datatype>] [-st <StartTime>] [-ut <UntilTime>] [-i <DefaultPriority>] [-o <Priority>] [<+|->shared] [<+|->direct] [<+|->hidden] [<+|->published] [<+|->rawonly] [<+|->queued] [<+|->enablebidi] [<+|->keepprintedjobs] [<+|->workoffline] [<+|->enabledevq] [<+|->docompletefirst]

Syntax Explanation

  • -g: Displays configuration information about a printer.
  • -t: Configures a printer.
  • -x: Renames a printer.
  • -S <ServerName>: Specifies the name of the remote computer that hosts the printer that you want to manage. If you do not specify a computer, the local computer is used.
  • -P <PrinterName>: Specifies the name of the printer that you want to manage. Required.
  • -z <NewPrinterName>: Specifies the new printer name. Requires the -x and -P parameters.
  • -u <UserName> -w <Password>: Specifies an account with permissions to connect to the computer that hosts the printer that you want to manage. All members of the target computer’s local Administrators group have these permissions, but the permissions can also be granted to other users. If you do not specify an account, you must be logged on under an account with these permissions for the command to work.
  • -r <PortName>: Specifies the port where the printer is connected. If this is a parallel or a serial port, then use the ID of the port (for example, LPT1 or COM1). If this is a TCP/IP port, use the port name that was specified when the port was added.
  • -l <Location>: Specifies the printer location, such as “Copy Room.”
  • -h <ShareName>: Specifies the printer’s share name.
  • -m <Comment>: Specifies the printer’s comment string.
  • -f <SeparatorFileName>: Specifies a file that contains the text that appears on the separator page.
  • -y <DataType>: Specifies the data types that the printer can accept.
  • -st <StartTime>: Configures the printer for limited availability. Specifies the time of day the printer is available. If you send a document to a printer when it is unavailable, the document is held (spooled) until the printer becomes available. You must specify time as a 24-hour clock. For example, to specify 11:00 P.M., type 2300.
  • -ut <EndTime>: Configures the printer for limited availability. Specifies the time of day the printer is no longer available. If you send a document to a printer when it is unavailable, the document is held (spooled) until the printer becomes available. You must specify time as a 24-hour clock. For example, to specify 11:00 P.M., type 2300.
  • -o <Priority>: Specifies a priority that the spooler uses to route print jobs into the print queue. A print queue with a higher priority receives all its jobs before any queue with a lower priority.
  • -i <DefaultPriority>: Specifies the default priority assigned to each print job.
  • {+|-}shared: Specifies whether this printer is shared on the network.
  • {+|-}direct: Specifies whether the document should be sent directly to the printer without being spooled.
  • {+|-}published: Specifies whether this printer should be published in Active Directory. If you publish the printer, other users can search for it based on its location and capabilities (such as color printing and stapling).
  • {+|-}hidden: Reserved function.
  • {+|-}rawonly: Specifies whether only raw data print jobs can be spooled in this queue.
  • {+ | -}queued: Specifies that the printer should not begin to print until after the last page of the document is spooled. The printing program is unavailable until the document has finished printing. However, using this parameter ensures that the whole document is available to the printer.
  • {+ | -}keepprintedjobs: Specifies whether the spooler should retain documents after they are printed. Enabling this option allows a user to resubmit a document to the printer from the print queue instead of from the printing program.
  • {+ | -}workoffline: Specifies whether a user is able to send print jobs to the print queue if the computer is not connected to the network.
  • {+ | -}enabledevq: Specifies whether print jobs that do not match the printer setup (for example, PostScript files spooled to non-PostScript printers) should be held in the queue rather than being printed.
  • {+ | -}docompletefirst: Specifies whether the spooler should send print jobs with a lower priority that have completed spooling before sending print jobs with a higher priority that have not completed spooling. If this option is enabled and no documents have completed spooling, the spooler will send larger documents before smaller ones. You should enable this option if you want to maximize printer efficiency at the cost of job priority. If this option is disabled, the spooler always sends higher priority jobs to their respective queues first.
  • {+ | -}enablebidi: Specifies whether the printer sends status information to the spooler.
  • /?: Displays help at the command prompt.

Explanation with Examples

To display configuration information for the printer named ColorPrinter_2 with a print queue hosted by the remote computer named HRServer:

cscript Prncnfg.vbs -g -S HRServer -P ColorPrinter_2

To configure a printer named ColorPrinter_2 so that the spooler in the remote computer named HRServer keeps print jobs after they have been printed:

cscript Prncnfg.vbs -t -S HRServer -P ColorPrinter_2 +keepprintedjobs

To change the name of a printer on the remote computer named HRServer from ColorPrinter_2 to ColorPrinter 3:

cscript prncnfg.vbs -x -S HRServer -P ColorPrinter_2 -z “ColorPrinter 3″

Popd

The popd command changes the current directory to the directory that was most recently stored by the pushd command. The pushd command saves the current working directory in memory so it can be returned to at any time.

Syntax (view syntax formatting guide):

popd

Syntax Explanation

  • /?: Displays help at the command prompt.

Every time you use the pushd command, a single directory is stored for your use. However, you can store multiple directories by using the pushd command multiple times.
The directories are stored sequentially in a virtual stack. If you use the pushd command once, the directory in which you use the command is placed at the bottom of the stack. If you use the command again, the second directory is placed on top of the first one. The process repeats every time you use the pushd command.
You can use the popd command to change the current directory to the directory most recently stored by the pushd command. If you use the popd command, the directory on the top of the stack is removed from the stack and the current directory is changed to that directory. If you use the popd command again, the next directory on the stack is removed.

When command extensions are enabled, the popd command removes any drive-letter assignations created by pushd.

Explanation with Examples

The following example shows how you can use the pushd command and the popd command to save and return to a current working directory:

C:usersTom>pushd /

C:>pobd

C:userTom>

 

Pause

The Pause command suspends the processing of a batch program and displays the following prompt:

Press any key to continue . . .

This is beneficial in case you do not wish to complete the batch program or perhaps you need to give the user a chance to insert a new disk into the drive before continuing the batch.

Syntax (view syntax formatting guide):

pause

Syntax Explanation

  • /?: Displays help at the command prompt.

When you run the pause command, the following message appears: 


Press any key to continue . . .

If you press CTRL+C to stop a batch program, the following message appears: 


Terminate batch job (Y/N)?


If you press Y (for yes) in response to this message, the batch program ends and control returns to the operating system.

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.

Explanation with Examples

To create a batch program that prompts the user to change disks in one of the drives:

@echo off
:Begin
copy a:*.*
echo Put a new disk into drive A
pause
goto begin

In this example, all the files on the disk in drive A are copied to the current directory. After the message prompts you to put a new disk in drive A, the pause command suspends processing so that you can change disks and then press any key to resume processing. This batch program runs in an endless loop—the goto begin command sends the command interpreter to the Begin label of the batch file. To stop this batch program, press CTRL+C and then press Y.