techhack.co.uk

Main menu

Skip to content
  • Home
  • Mobile
    • Android
  • Security
    • Malware, Spyware and Viruses
  • Software
    • Firefox
    • IE
    • Office
    • Thunderbird
  • Web
    • Apache
    • CSS
    • Email
    • MySQL
    • SEO
    • WordPress
  • Windows
    • Printers
    • Server
    • Windows 7

Post navigation

← Previous Next →
Printer

Install printers on login using a VBScript

Posted on September 4, 2011 by Robert Longworth

To save yourself the manual work of installing printers on client pc you could write a short bit of code to get this to happen automatically on login, with the use of a simple VBScript, particularly useful in a large company or organisation such as a school where there could be 100′s of PCs to setup.

The process will consist of 2 stages. Firstly we want to run the VBScript on login. If you already use a login bat on login to perform tasks such as mapping network drives then you could do this by adding the following line to the login bat file to call the VBScript.

WScript.exe "\\SERVERNAME\SYSVOL\DOMAINNAME\scripts\SCRIPTNAME.vbs"

Where you would replace the SERVERNAME, DOMAINNAME and SCRIPTNAME with your own configuration.

If you don’t run a login.bat then you could set the VBScript to be called in the Active Directory, as shown below. This option is under the profile tab of a users account.

Login script

The second stage is the VBScript itself.

On Error Resume Next
Set netPrinter = CreateObject("WScript.Network")
netPrinter.AddWindowsPrinterConnection "\\SERVERNAME\PRINTERNAME"
netPrinter.SetDefaultPrinter "\\SERVERNAME\PRINTERNAME"

Lets go into a little more detail. The first line pretty much explains itself, if there are any problems the script won’t simply holt but jump onto the next line and attempt to continue running. The second line is creating an object of type WScript.Network. The third line is where you will want to begin tailoring it to your own scenario, this is adding a connection for the printer, here you should add the hostname or IP address of the machine the printer is installed upon, followed by the name of the printer itself. Finally if you are adding multiple printers, using the fourth line of code, you could set which printer you would like to be the default printer.

Posted in Printers, Windows | Tagged automatic, install, login, printer, VBScript

Recent Posts

  • Restore MySQL database from .frm files
  • Fix for Outlook 2010 “None of your e-mail accounts could send to this recipient.”
  • cmd asking to “Open With”
  • Make your website more mobile friendly
  • Install printers on login using a VBScript
  • CSS transitional effect example
  • Extract a print driver .inf from an executable .exe
  • A simple cmd batch script to backup MYSQL for WAMP servers

Archives

  • December 2011 (1)
  • September 2011 (6)
  • May 2011 (1)
  • April 2011 (1)
  • March 2011 (6)
  • February 2011 (17)

Tag Cloud

.htaccess about:config add_filter apache authentication cmd command prompt css Custom Directory Index Custom Directory Index Files Custom Error Pages Default font settings email excerpt excerpt_length excerpt_more explorer.exe File and directory access control Firefox generator improving search engine ranking install meta Microsoft Office 2010 Microsoft Office Word 2010 Modifying Environment Variables Mozilla MS Office Word 2010 MYSQL Notepad printer search engine optimisation security seo Shortcut Show Desktop spell check spell correct spelling Taskbar Thunderbird Windows Windows 7 WordPress word template