hi, still no joy i'm affraid..
When i replace the 'elseif' for 'case' the printer defaults to the PR03 (the first in the list), when i use the 'elseif' it sets the default as PR11 but if i set my dept as sales instead of IT it doesnt set the default as PR09 as it should.
any ideas??
the full script to remove all network printers, add printers and set deafults is below.
any help/advise is appreciated
' Script to add network printers to workstations and thin clients
' Declare variables and enumerate existing printer connections
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Dim computerName
computerName = LCase(WshNetwork.ComputerName)
' Delete existing connections to network printers
For i = 0 to oPrinters.Count - 1 Step 2
On Error Resume Next
if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
else WScript.Echo "No network printers found"
end if
Next
' Add printer connections dependant upon location
' Variable to select print server
Dim printServer
printServer = "SVGFP01"
' VBScript.
Set net = WScript.CreateObject("wscript.network")
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 Swan"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR05"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR08"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR09"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR10"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 A3"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 Powerforce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR13"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR16"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR17"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR18"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR19"
Dim qQuery, objSysInfo, objuser
Dim Department
Department = objUser.Department
if objUser.Department = "IT" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11"
elseif objUser.Department = "Purchasing" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11 RKW"
elseif objUser.Department = "Sales" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR09"
elseif objUser.Department = "Accounts" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR03"
elseif objUser.Department = "QA" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR16"
elseif objUser.Department = "Warehouse" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR04"
elseif objUser.Department = "Swan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
elseif objUser.Department = "Returns" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
elseif objUser.Department = "Dan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR19"
objUser.Department = "Traffic"
net.SetDefaultPrinter "\\svgfp01\GBSTORPR08"
end if
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114:





by: RolandDeschainPosted on 2009-08-24 at 04:49:07ID: 25167372
Use "Select case" instead of elseif, as in attached code.
If still don't work, then the problem is not in the selector clause.
Select allOpen in new window