Related Items  

Linux Consulting  

Login or Register  

If you wish to contribute an article, please login or register.

Adding a printer using scripts (Windows)

PrintE-mail

VBSccript_file_format_iconQ. 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.

Using batch:

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:

Option Explicit
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

'Add printers
strPort = LPT2
strUNCPrinter = "\\servername\printername"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.AddPrinterConnection strPort,strUNCPrinter
objPrinter.SetDefaultPrinter strUNCPrinter

WScript.Quit

Good luck.

Comments (1)
Thanks
1 Wednesday, 29 June 2011 12:22
JJ
Thank you - that worked (Windows 7 64-bit)

Add your comment

Your name:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.24.0
   
Copyright © 1999 - 2014 Virtual Helpme | t | Original Template: Allrounder