VB Logon Script for connecting 2 printers, one default

Posted on 2005-03-30
Medium Priority
Last Modified: 2010-04-10

I need a Visual basic Logon script which will connect two network printers (call them hpl and hpd, I'll change the UNC) and set hpl as the default printer.

This script should also remove any current network printers (it shouldn't remove the "office imaging document converter or w/e)


Also, is there a way to "hide" the "office document image writer," it always confuses my employees. Thanks.
Question by:ubers0ldat
  • 2
LVL 76

Accepted Solution

David Lee earned 1000 total points
ID: 13668136
Hi ubers0ldat,

This should do it.  Note that this approach installs the printer driver, if it's not already installed and therefore could be slow over a slow link.

    Set objNetwork = CreateObject("Wscript.Network")
    objNetwork.AddWindowsPrinterConnection "\\Server\hpl"
    objNetwork.AddWindowsPrinterConnection "\\Server\hpd"
    objNetwork.SetDefaultPrinter "\\Server\hpl"
    Set objNetwork = Nothing

I don't know of any way to hide a printer entry.


Assisted Solution

PaulLG earned 1000 total points
ID: 13670149

Use the following code to delete unwanted printers.
Add/amend a Case statement for the name of the printers you want to keep, any others will bedelete by the Case Else.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Select Case objPrinter.name
      Case "Your printer name here"
            'do nothing
      Case "another printer name"
            'do nothing
      Case Else
End Select

If you change the permissions to the office document image writer so that users do not have print permission, this might stop them from seeing it.

Paul L
LVL 76

Expert Comment

by:David Lee
ID: 14246658
Recommend splitting the points between PaulG and myself.

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
This program is used to assist in finding and resolving common problems with wireless connections.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question