Adding a printer using scripts (Windows)
Q. I would like to be able to add a printer using a login/startup script in windows.
A. There are several ways to do so. You can use VBS scripts or batch scripts.
rundll32 printui.dll,PrintUIEntry /in /n \\server\printername
rundll32 printui.dll,PrintUIEntry /in /n \\server\printername /y
The above adds the printer (first line) and makes it default (second line). This is to add the printer for a particular user. It may be that the user is not authorized to add the printer and you may get an error:
You do not have sufficient access to your computer to connect to the selected printer.
In that case, you'll have to run the script as an aministrator on the computer and add the printer to the system globally, not just the one user:
rundll32 printui.dll,PrintUIEntry /ga /c\\computername /n\\server\printername
If you are adding the above to a login script replace computername with %COMPUTERNAME%. This way it will automatically insert the name of the current computer.
To delete the printer globally, run the following:
rundll32 printui.dll,PrintUIEntry /gd /c\\computername /n\\server\printername
Using VB Script:
On Error Resume Next
' Initializes Vars
Dim strPort, strUNCPrinter, objNetwork
strPort = ""
strUNCPrinter = ""
' Constructs Object to get login info.
set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName
strPort = LPT2
strUNCPrinter = "\\servername\printername"
Set objNetwork = CreateObject("WScript.Network")
Last Updated on Wednesday, 27 July 2011 10:40