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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

765 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