How to add multiple printers using AD/OU/Computers using a vbscript?

C

Cary Shultz

-----Original Message-----
How to add multiple printers using AD/OU/Computers using a vbscript?

I have successfully implemented a automatically installed single printer
(default) based on AD/OU/Users using Microsoft KB 263226.

I however can not get the same script to run based on AD/OU/Computer. Why
will it not work based on computer?

Based on the assumption that it will only work on Users, how can I use a
vbscript to add multiple printers using either AD/OU/Users?

NOTE: I have tried to simply add the additional printers without
success...e.g.

Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\Server\Printer"
PrinterDriver = "PrinterDriver"
PrinterPath2 = "\\Server\Printer2"
PrinterDriver2 = "PrinterDriver2"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork.AddWindowsPrinterConnection PrinterPath2, PrinterDriver2
WshNetwork.SetDefaultPrinter "\\Server\Printer"

Thanks for any help.

Scott


.
Scott,

I am realtively new to vbs scripting ( finally breaking
away from .bat and .cmd! ) but will try my best.

It looks like you are following one of the scripts via the
Script Center ( or whatever it is called - have not had
the time in the last three weeks to go back there ).

Here is how I would write it using the script "format"
that you are using and then one that I have used a few
times with success:

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("Wscript.Network")
Printerpath = "\\Server\printer"
WshNetwork.AddWindowsPrinterConnection PrinterPath


Here is the one that I have used before:

Dim net
Set net = CreateObject("Wscript.Network")
net.RemoveNetworkDrive "O:"
net.MapNetworkDrive "O:", "\\server\sharename","False"
net.RemoveNetworkDrive "P:"
net.MapNetworkDrive "P:", "\\server\sharename","False"
net.AddWindowsPrinterConnection "\\server\printshare1"
net.AddWindowsPrinterConnection "\\server\printshare2"
net.AddWindowsPrinterConnection "\\server\printshare3"
net.SetDefaultPrinter "\\server\printshare2"

I have included in the example some mapped network drives
as well as three printers, setting the second printer as
the default printer. It is important to include
the "false" at the end of the network drive mappings,
otherwise the second, third and each subsequent time the
users logon they will get an error message. It
essentially says "this is not a persistent mapping".

I would call this logon.vbs and use Group Policy as a
logon script and apply it to the OU which contains the
user accounts to which you want this logon script
applied. It works very very well with WIN2000 and WINXP
clients.

HTH,

Cary
 
S

Scott

Cary,

Thanks. I will build and test the script with your suggestions...what are
your thoughts about setting up a script that can follow a user. That way
the user doesn't even have to change the default printer to the room he/she
is in, they can simply login and print to the nearest printer.
E.g. John is a professor that logs into 2 workstations each day. The first
is in the West Wing of the building using PRINTER1 and the second is in the
East Wing of the building PRINTER2 (1/4 mile apart). The two locations have
there own printers and it would be nice to have the default printer set for
each room for each user that logs in....I guess I would call it SNPSAD
(Select Nearest Printer Set As Default).

Thanks again,

Scott
 
C

Cary Shultz

-----Original Message-----
Cary,

Thanks. I will build and test the script with your suggestions...what are
your thoughts about setting up a script that can follow a user. That way
the user doesn't even have to change the default printer to the room he/she
is in, they can simply login and print to the nearest printer.
E.g. John is a professor that logs into 2 workstations each day. The first
is in the West Wing of the building using PRINTER1 and the second is in the
East Wing of the building PRINTER2 (1/4 mile apart). The two locations have
there own printers and it would be nice to have the default printer set for
each room for each user that logs in....I guess I would call it SNPSAD
(Select Nearest Printer Set As Default).

Thanks again,

Scott




.
Scott,

As I said, I am only beginning to use vbs for scripting.
I would have to look into it more.

Not that this answers your question, but it could be
*possible* to include in the logon script the two or three
printers that the user would use, you dictate which one is
the default, and when he goes to the other building and
logs on he simply needs to remember to change the default
printer ( or use File | Print and then select the printer
he wants vs. simply hitting the print icon ). I hate to
suggest this because it is our job to make things as easy
as possible for our users.

I will look - if I have the time today - to see if there
is a possibility to implement your SNP ( Slect Nearest
Printer ) via vbs scripting...

Cary
 
C

Cary Shultz

-----Original Message-----
a
user. That way The
two locations have
Scott,

As I said, I am only beginning to use vbs for scripting.
I would have to look into it more.

Not that this answers your question, but it could be
*possible* to include in the logon script the two or three
printers that the user would use, you dictate which one is
the default, and when he goes to the other building and
logs on he simply needs to remember to change the default
printer ( or use File | Print and then select the printer
he wants vs. simply hitting the print icon ). I hate to
suggest this because it is our job to make things as easy
as possible for our users.

I will look - if I have the time today - to see if there
is a possibility to implement your SNP ( Slect Nearest
Printer ) via vbs scripting...

Cary
.
Hey,

I found something while my wife was at Cheerleading
practice. Take a look at pages 930 - 933 in Mark
Minasi's "Mastering Windows 2000 Server" Fourth Edition.

There are three example scripts that might come into play
for you. The first one is a generic script. The second
one is a Computer- or User-specific script and the third
one is Location-specific script.

Again, these three are from pages 930 - 933 from Mark
Minasi's "Mastering Windows 2000 Server" Fourth Edition:

+++++++++++++++++++++++++++++++++++++++++++++++++++

Option Explicit
Dim oNetwork, sPrintPath
Set oNetwork = CreateObject("WScript.Network")
sPrintPath = "\\servername\printername"
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath
Set oNetwork = vbEpty
Set sPrintPath = vbEmpty

+++++++++++++++++++++++++++++++++++++++++++++++++++++


=====================================================

Option Explicit
Dim oNetwork, sPrintPath
Set oNetwork = CreateObject("WScript.Network")
Select Case oNetwork.ComputerName
Case "Gamma" --- this would be the name of your computer
sPrintPath = "\\server\printer1"
Case "Geektoy"
sPrintPath = "\\server\printer2"
Case Else
sPrintPath = "\\server\printer3"
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath
Set oNetwork = vbEmpty
Set sPrintPath = vbEmpty

=====================================================

+++++++++++++++++++++++++++++++++++++++++++++++++++++

Option Explicit
Dim oNetowrk, sPrintPath, sLocate
Set oNetwork = CreateObject("WScript.Network")
sLocate =_
InputBox(Where are you? Type 'Lab', or 'Reception'.")
Select Case sLocate
Case 'Lab'
sPrintPath = "\\server\printer1"
Case 'Reception'
sPrintPath = "\\server\printer2'
Case Else
Wscript.Echo "That is not a valid
choice." :Wscript.Quit
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath
Set oNetwork = vbEmpty
Set sPrintPath = vbEmpty

=====================================================

HTH,

Cary
 

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