VBS Printer Logon Scripts for Computers
Introduction to Printer Logon Scripts for Computers
What people want is a Windows logon script that will assign a printer to a computer - not a user. My advice is, find another way! At least reconsider your strategy, redefine the problem and see how far you could get assigning a printer to all users or some other way.
O.K, you still want a script that will map a printer to a computer. Even though I don't like the idea, I will give it my best shot, as ever I will tell you all that I know.
Topics for Printer Logon Scripts for Computers
Let us begin with the computer start up sequence. The Windows operating boots up, a logon box appears and is waiting for a username and password. Meanwhile, any computer logon scripts run, the operating system processes the computer section of the registry. So far so good. However, if you try and run a script that maps a printer to all the users who logon, it just doesn't work. Even if you try assigning print permissions to the computer - no good. To my logic, this makes sense because otherwise, the operating system could create a printer for a user, who had been absolutely denied print permission on this particular printer share.
By all means experiment, do tell me if I have missed a trick with a StartUp computer script. However, do be careful, I once got carried away with the scripting, and put a pause statement in a computer script. Nasty. The machine just hung because no-one could, 'press any key to continue'. Fortunately, I got out of the viscous loop thanks to Remote Desktop.
Four readers ride to my rescue
Remember that our goal is to assign a network printer to a computer, no matter who logs on. The best part of this saga is the positive power of the internet. I have never met these four kind gentlemen, nevertheless they came to my assistance.
Ben produced a wonderful example of lateral thinking. He uses the little known loopback method available in Group Policies. What loopback does is turn the computer into a kiosk. No user settings are applied, only computer setting - this just what we want.
In Group Policy navigate to:
Once Ben set the loopback processing, his printer scripts executed, even when he applied them to the computer and not the user.
The key technique is rundll32 printui.dll,PrintUIEntry.
1) This installs printer quietly
rundll32 printui.dll,PrintUIEntry /in /q /n\\servername\printername
2) This deletes the networked printer from the machine being logged onto, and does so quietly.
3) This Sets the default printer
I like the Permissions Monitor because it enables me to see quickly WHO has permissions to do WHAT. When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!
Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource. Give this permissions monitor a try - it's free!
Warning this script will need adjustment for your environment. For example edit the set pserver = CLTLBXPRN
Warning this script is viscous and will delete all your mapped printers.
echo Remove All Network Printers.......
echo Show All Available Printers From %pserver%.......
net view %pserver%
set /p pname= Enter Printer Name:
rundll32 printui.dll,PrintUIEntry /in /n\\%pserver%\%pname% /q
Kim Øystein Næss - Improvement by adding /ga
Command Line: rundll32 printui.dll PrintUIEntry /ga /n\\machine\printer
Adds a per-machine connection to the client machine. A per-machine connection is a printer configured to be accessible by all users of the client machine. Normally, when a user adds a printer to a client machine, the printer is visible only to the account used by the person adding the printer. This command must be run by a local admin of the client machine. The /ga switch is the key component which previous examples lacked.
Here is a little research that Guy undertook.
1) Check that RUNDLL32 PRINTUI.DLL,PrintUIEntry /? works on your machine, I mention this as it only seems to work on Windows 2003, XP and Windows 2003 machines.
2) Amongst the zillions of switches it seemed that the example: /in
3) /y /n Worked to set the default printer. /y /n "Printer Name"
4) /ge /c \\machine also worked.
That was as far as I got, tantalizing and frustrating. And then Ian P. kindly sent in the fruits of his research
After some trial and error Ian came up with the following examples that worked
below adds the printer called PAN_FINANCE to the local PC. The PrintServer on the Domain is PNZ_PS
The below then sets that printer to be the default printer
Here are Guy's original sources of information: Technet Q189105
Guy Recommends SolarWinds' Free Network Monitor
Thus utility makes it easy to check the health of a router or firewall. Check the real-time performance, and availability statistics, for any device on your network. Get started with an extensive collection of "out-of-the-box" monitors for popular network devices. Give Network Monitor a whirl - it's free. Download your free Network Device Monitor
If you need more comprehensive
network analysis software:
Naturally you'll need to change values such as the IP address and printer information to suit your situation.
strComputer = "."
objNewPort.Name = "192.168.2.71"
Set objWMIService = GetObject("winmgmts:" _
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = " Lexmark E260dn "
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "Lexmark E260dn"
Our mission is to create a script which will map a printer to a computer. Who ever logs on will find your choice of printer in their Printers and Faxes folder. At times this project seemed like mission impossible but thanks to Ben, Pete and Randy, we got the job done.
See more printer logon scripts examples