Managing printers is an unexciting but unavoidable responsibility for Windows systems administrators. Microsoft has put a lot of work into the Windows GUI to make printers easier to find and install, but users are still responsible for adding the printers they need to use. When printers are located together geographically or when users always log on to the same computers, adding printers can potentially be a one-time event. However, when users log on to computers in different geographical areas, adding printers can become a fairly regular occurrence. Depending on the number of users and their level of sophistication (or lack thereof), finding and installing printers can generate a lot of Help desk calls.
One reason why users might need help is that Windows' Add Printer wizard only adds printers to the current user's profile. Unfortunately, there's no option in the GUI to log on as an administrator and add one or more printers that will appear for all users. The problem gets even more complicated when a print server needs to be upgraded or replaced and users have to add the new and delete the old printers.
Microsoft must have recognized this limitation, so starting in Windows 2000, it introduced the ability to add per-machine printer connections to a computer. A per-machine printer connection is a network printer connection that appears for all users. This capability lets you add a printer to a computer only once, and any user that logs on to the computer sees the printer. Users only need to be shown how to set their default printer. In addition, in cases in which a print server is replaced, you can simply delete the old per-machine printer connections and add the new per-machine printer connections. In this scenario, users no longer need to worry about adding and deleting their own printers if the required printers are already available to them.
Strangely, this useful capability isn't well documented. Even worse, the only way to take advantage of per-machine printer connections is to type long, cumbersome commands. For example, to add the printer \\PS3\HP 4600dn as a per-machine printer connection to the computer COMPUTER2, you have to type the command
/c\\COMPUTER2 /ga
/n"\\PS3\HP 4600dn"
To list the per-machine printer connections on COMPUTER2, you have to run the command
rundll32 printui.dll,PrintUIEntry
/c\\COMPUTER2
/ge /f"C:\Printers.txt"
This command saves COMPUTER2's list of per-machine printer connections in a text file named C:\Printers.txt. However, this file contains more than just the printer names, so you have to edit or parse it to extract just the printer names.
As you can see, the command-based interface for managing per-machine printer connections is awkward. I needed a better solution, so I created the PMPMgr plug-in that lets me manage per-machine printer connections more easily. This plug-in consists of a Windows Script Components (WSC) file named PMPMgr.wsc and a script named PMPMgr.js. The PMPMgr plug-in provides an easy-to-use command-line interface for managing per-machine printer connections. You can download the PMPMgr plug-in by clicking the Download the Code button at the top of the Web page. To use this plug-in, you don't need to adapt the PMPMgr.wsc and PMPMgr.js files in any way. You just need to perform four steps:
- Register PMPMgr.wsc.
- Learn the PMPMgr.js command-line syntax.
- List the shared or per-machine printer connections.
- Add or delete per-machine printer connections.
STEP 1: Register PMPMgr.wsc
Before you can use the PMPMgr plug-in to manage your per-machine printer connections, you must register the PMPMgr.wsc component. The registration process adds the registry entries that make the component's object available to the system. To register the component, right-click the PMPMgr.wsc file in Windows Explorer and choose Register. Alternatively, you can register it from the command line with the command
regsvr32 /i:"[path\]PMPMgr.wsc"
%SystemRoot%\system32\scrobj.dll
where path is the path to the component on your system. (Although this command appears on several lines here, you would enter it on one line in the command-shell window. The same holds true for the other multiline commands in this article.) Conversely, if you want to unregister the component, right-click the PMPMgr.wsc file and choose Unregister. To unregister it from the command line, type the command
regsvr32 /u /n /i:"[path\]PMPMgr.wsc"
%SystemRoot%\system32\scrobj.dll
To run either command without displaying the dialog box message, add the /s option immediately after regsvr32 in the commands just given. You must be a member of the local Administrators group to register or unregister the component.
STEP 2: Learn the PMPMgr.js Command-Line Syntax
After you've registered the PMPMgr.wsc component, you'll be able to use PMPMgr.js. This script's command-line syntax is as follows:
[cscript] PMPMgr.js [[@]computer]
/shared | /list | /exists:[@]printer |
/add:[@]printer | /delete:[@]printer
Here's a description of each syntax element:
- The cscript keyword at the beginning of the command is only required when CScript isn't your default script host. To set CScript as your default host, run the command
cscript //H:CScript //Nologo //S
- The computer argument specifies a computer name. If you use the @ character, the computer argument refers to a text file containing a list of computer names (one name per line). If you don't specify this argument, PMPMgr.js assumes the current computer.
- The /shared option lists the printers shared from the print server(s) specified by the computer argument.
- The /list option lists the per-machine printer connections on the computer(s) specified by the computer argument.
- The printer argument specifies a printer name in Universal Naming Convention (UNC) format (\\printserver\printername). If the printer name contains spaces, enclose it in double quotes (" "). If you use the @ character, the printer argument refers to a text file containing printer names in UNC format (one name per line).
- The /add option adds the per-machine printer connection(s) specified by the printer argument.
- The /delete option deletes the per-machine printer connection(s) specified by the printer argument.
STEP 3: List the Shared or Per-Machine Printer Connections
The PMPMgr.js script's /shared option lists the shared printers shared from a print server. For example, you can run the following command to list the printers on the print server named PS1:
PMPMgr.js PS1 /shared
PMPMgr.js produces tab-delimited output that you can redirect to a text file. Figure 1 shows an example of the script's output.
You can also list the printers shared from multiple print servers with a single command. Place a list of print servers in a text file, and specify the text file's name immediately following the @ character. Figure 2 shows a sample text file, PrintServers.txt. The following command lists the shared printers for each computer specified in the Print-Servers.txt input file and redirects the results to the PrintServers.tsv output file:
PMPMgr.js @PrintServers.txt
/shared > PrintServers.tsv
To list the per-machine printer connections installed on one or more computers, use the /list option instead of the /shared option in the command just given.
STEP 4: Add or Delete Per-Machine Printer Connections
To add or delete per-machine printer connections, you use the PMPMgr.js script's /add or /delete option, respectively. For example, the following command adds the printer \\PS2\HP LaserJet 1300 to the computer RECEPTION1:
PMPMgr.js RECEPTION1
/add:"\\PS2\HP LaserJet 1300"
To add or delete multiple printers at once, you can create a text file that contains a list of printers, one printer per line. Figure 3 shows a sample text file, Printers.txt, that contains a list of printers. The following command adds the printers in listed Printers.txt to the computer RECEPTION2:
PMPMgr.js RECEPTION2
/add:@Printers.txt
Note that if a user is logged on when you add or delete per-machine printers, the changes won't appear in the user's Printers window until the next time he or she logs on. To see the changes immediately, you need to restart the computer's Print Spooler service.
I designed the PMPMgr.wsc component and PMPMgr.js script to be tolerant of errors, but you must run PMPMgr.js under an account that's a member of the current computer's local Administrators group. If you're working with remote computers, you must be a member of each remote computer's local Administrators group as well. If you run PMPMgr.js under an account with insufficient permissions, you might see a Printer User Interface dialog box, which will pause the script. You must dismiss the dialog box before the script will continue.
A Better Way to Manage Printers
Per-machine printer connections have saved me a lot of time and trouble. The PMPMgr plug-in makes using these connections much easier. Download the PMPMgr.wsc and PMPMgr.js files and start taking advantage of per-machine printer connections today.
Solution Snapshot
PROBLEM: The command-based interface to manage per-machine printer connections in Windows 2000 and later is awkward.
SOLUTION: Use the PMPMgr plug-in to more easily manage per-machine printer connections.
WHAT YOU NEED: PMPMgr.wsc, PMPMgr.js, Windows 2000 or later, Windows Script Host (WSH) 5.6
DIFFICULTY:
3 out of 5
SOLUTION STEPS:
- Register PMPMgr.wsc.
- Learn the PMPMgr.js command-line syntax.
- List the shared or per-machine printer connections.
- Add or delete per-machine printer connections.
|
Cool. I've been looking for a way to do this for ages...
How do I download.. I don't see a download link
How do I download.. I don't see a download link
Hi there, I have tried your utility and it seems to work fine till I register it and use it to view shared printers on my server. However when I try to list machine connected printers for any network computer or add a machine connected printer to any network computer (the whole point of the utility), it throws and error saying it couldn't enumerate printers because the Print Spooler service is not runnig. Now I have checked on both computers i.e. the server and where I want printers added, the Print Spooler service is running and also set to Automatic. Not sure what is going wrong here. I have tried restarting the service as well but no help. Has anyone come across this problem and resolved it? If yes then reply please.
I was able to use the native windows printui.dll commands. When I tried to use the utility I got an error at line 330, 'named' is null, or not an object. When I try to set cscript as default I got a message saying that the scripting language could not be changed. However, I recieved line error 330 even when using cscript to run the script explicitly.
Great idea but keep in mind any printers setup this way will need to be deleted this way. In looking at this printui.dll function in months past I finally found it only 1/2 useful I found no way to set the newly installed printer on the remote machine as default...what gives?
mnit: Make sure the Windows firewall isn't blocking connections. j.e.taylor: My guess is you're usin a Windows 2000 machine without WSH 5.6. Install IE 6 or WSH 5.6. jhusted: As the article states, "Users only need to be shown how to set their default printer." That's separate from what the script component and command-line utility does. Regards, Bill
Using a logon script in a GPO is a much better way to go, unless the network is very small, and without a domain. You can set the default printer, automatically prune printers that have been disconnected, use conditional statements for different users or computers...
Sounds great. Hoping that commenting will reveal dl link...
sandiegocal: I respectfully disagree with your assertion. Your solution may be viable for a larger network where administrators have scripting experience, but I think per-machine printers are simpler. Everyone else: To see the download link, you have to create a logon ID and associate it with your subscription number. Regards, Bill
Still trying to locate the download link. I would really like to know where the others found the files to test with. Please assist.
Just played around with this and I think it'll be incredibly useful in my enviroment (1,000 users spread over 48 locations). The login script / GPO solution might work if you have the time and/or staff to devote to it, but this is quick, simple and easy. Now, new machines we configure can go out with all printers easily without adding by hand. Or, when we replace a server, we can easily update all the clients' printers. Love it! Thanks!
HOW CAN DOWNLOAD THE TOOLS.
Yes, where is the download. I don't see it on this site and have got on this site and checked for at least 4 different times.
To all who couldn't download the code: This article was formerly subscriber-only, so if you weren't a Windows IT Pro subscriber, you could not access the code or read the entire article. I've made the article available to registered users for a limited time so you can download the code and read the full article. Note that if you aren't a subscriber, for only $5.95 you can get a monthly pass that will let you access all subscriber-only articles for 30 days. (See link at the top of the page.) Thanks for reading!