Help with script for adding printers when user logs on

  • Thread starter cheung.jccheung
  • Start date
C

cheung.jccheung

Hi,
I have a logon script for users at my office which adds all the network
printers:

Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501N"
WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501NPCL6"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPLJ5000PCL5e"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPDJ800PS"
WshNetwork.AddWindowsPrinterConnection "\\RHA17\ESPR1800"

The script works wonderfully, the only problem is when someone logs
into RHA17. When they log in, Windows gives an error because the
printer is already attached locally. I cannot move the printer because
it loses certain functionalities when shared through a print server. Is
there a way to set an if then statement in the script that checks
whether the computer that the user is logging into is RHA17?
Thanks for your help!
 
J

Jerold Schulman

Hi,
I have a logon script for users at my office which adds all the network
printers:

Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501N"
WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501NPCL6"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPLJ5000PCL5e"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPDJ800PS"
WshNetwork.AddWindowsPrinterConnection "\\RHA17\ESPR1800"

The script works wonderfully, the only problem is when someone logs
into RHA17. When they log in, Windows gives an error because the
printer is already attached locally. I cannot move the printer because
it loses certain functionalities when shared through a print server. Is
there a way to set an if then statement in the script that checks
whether the computer that the user is logging into is RHA17?
Thanks for your help!

Set oShell = CreateObject( "WScript.Shell" )
comp=oShell.ExpandEnvironmentStrings("%ComputerName%")
Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501N"
WshNetwork.AddWindowsPrinterConnection "\\cm4\SMX3501NPCL6"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPLJ5000PCL5e"
WshNetwork.AddWindowsPrinterConnection "\\cm4\HPDJ800PS"
if UCASE(comp) <> "RHA117" Then
WshNetwork.AddWindowsPrinterConnection "\\RHA17\ESPR1800"
End If


See tip 9956 » How do I use an environment variable in VBScript?
in the 'Tips & Tricks' at http://www.jsifaq.com


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top