Exactly as the others have said.  You can't make a single variable hold two different connect strings...  You can re-assign the strConnectString variable each time and then call the wshNetwork.AddWindowsPrinterConnection as such...
 

Set objWSHNetwork = CreateObject("WScript.Network") 'create network object

strConnectString = "\\servername\Boston_IT2"
strResult =objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

 

strConnectString = "\\servername\Boston_IT"
strResult =objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

 

etc etc

 

If you want cleaner code, you can use a Scripting Dictionary object as such:

 

----

Set objWSHNetwork = CreateObject("WScript.Network") 'create network object

 

Set strConnectString = CreateObject("Scripting.Dictionary")

 

strConnectString.add "PrinterA", "\\servername\Boston_IT2"
strConnectString.add "PrinterB", "\\servername\Boston_IT"
strConnectString.add "PrinterC", "\\servername\Boston_IT3"

 

for each elem in strConnectString 
    strResult =objWSHNetwork.AddWindowsPrinterConnection(strConnectString(elem))
next

----
 
To add or remove printers, just add another line of strConnectString.add "_PrinterName_", "_PrinterConnectString_"
 
Just replace the PrinterName (anything you want to call it, so long as it's not the same as any other) and PrinterConnectString with appropriate values.

 

Joe Pochedley
A computer terminal is not some clunky old television
with a typewriter in front of it. It is an interface
where the mind and body can connect with the universe
and move bits of it about. -Douglas Adams

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kevin Sullivan
Sent: Tuesday, April 12, 2005 4:55 PM
To: [email protected]
Subject: RE: [ActiveDir] VB Script and Group policy

strConnectString is only going to carry one value to the strResult…

 

You need to create a loop or do it one at a time. Also not a VBScript person but maybe

 

Set wshNetwork = CreateObject("WScript.Network")

wshNetwork.AddWindowsPrinterConnection "\\2k3dc\HP6"

 

Set wshNetwork = CreateObject("WScript.network")

wshNetwork.AddWindowsPrinterconnection \\2k3dc\HPSales

 

Setup each printer as a separate section. The problem is apparently that your AddWindowsPrinterConnections usees strConnectString and you are expecting it to hold two strings… it only holds one. So your second strConnectString line essentially overwrites the first. I think this is right.. It may not be the ‘best’ way to do it but it should work…

 

Kevin

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christine Allen
Sent: Tuesday, April 12, 2005 4:19 PM
To: '[email protected]'
Subject: [ActiveDir] VB Script and Group policy

 

Running Windows 2000 AD

 

I'm looking to automate the installation of printers using a vb script and group policy.  I found the script referenced below which works great for adding the printer and works great with GP.  However, I can only add one printer.  Every time I modify it to add additional printers it only adds one.

 

Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
strConnectString = "\\servername\Boston_IT2"
strConnectString = "\\servername\Boston_IT"
strResult =objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

 

Does anyone out there know a way of additional multiple printers with this script?  I should mention I am not a vb person.

 

Thanks

Reply via email to