actech Posted June 19, 2009 Posted June 19, 2009 I have a printer in each computer lab which are set via the logon script. Lately however they have not always been going right. Sometimes random computers are mapping to a single printer in one room. Nothing has changed in the script, and it seems to be random. Would it be better to map the via GPO?? How much does this take? For reference here is an example of the script ' Create printers for computers in Room 214 cmp = InStr( 1, strComputerName, "ACW-214", 1) If cmp > 0 Then objNet.RemovePrinterConnection ( "\\Sun\HP1200-102" ) , true, true objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-214" ) objNet.SetDefaultPrinter( "\\Sun\HP1200-214" ) WScript.Quit End If
contink Posted June 19, 2009 Posted June 19, 2009 I'd need to see the whole script... as it stands that nugget just stops when it finds the right printer and has added it.
actech Posted June 19, 2009 Author Posted June 19, 2009 This is the whole section of the script that maps the printers. The section above is not for the first printer, which makes it a not more confusing for me. I am not overly converse with vb but know enough to get around. blnLocal = FALSE strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer") For Each objPrinter in colPrinters If objPrinter.Attributes And 64 Then blnLocal = TRUE End If Next If blnLocal = FALSE Then ' Variables declaration Dim objNet, strComputerName, cmp ' Read NetBIOS computer name Set objNet = WScript.CreateObject( "WScript.Network" ) strComputerName = objNet.ComputerName 'Remove obsolete Printers 'objNet.RemovePrinterConnection ( "\\Sun\iR5200 - Admin" ) , true, true 'objNet.RemovePrinterConnection ( "\\Sun\iR5200 - Admin" ) , true, true ' Create printers for computers in Staff Room cmp = InStr( 1, strComputerName, "ACW-STAFF", 1) If cmp > 0 Then objNet.AddWindowsPrinterConnection( "\\Sun\iR5200 - Admin" ) objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Staff" ) ' objNet.AddWindowsPrinterConnection( "\\Sun\T8024-Admin" ) ' objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Admin" ) objNet.SetDefaultPrinter( "\\sun\HP2015n-Staff" ) WScript.Quit End If ' Create printers for computers on Staff Laptops cmp = InStr( 1, strComputerName, "ACW-LT", 1) If cmp > 0 Then ' objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Lib" ) objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-214" ) objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-102" ) objNet.AddWindowsPrinterConnection( "\\Sun\iR5200 - Admin" ) objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Staff" ) ' objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Admin" ) ' objNet.AddWindowsPrinterConnection( "\\Sun\T8024-Admin" ) objNet.SetDefaultPrinter( "\\sun\HP2015n-Staff" ) WScript.Quit End If ' Create printers for computers in Admin cmp = InStr( 1, strComputerName, "ACW-ADMIN", 1) If cmp > 0 Then objNet.AddWindowsPrinterConnection( "\\Sun\iR5200 - Admin" ) objNet.AddWindowsPrinterConnection( "\\Sun\HP2015n-Staff" ) objNet.AddWindowsPrinterConnection( "\\Sun\T8024-Admin" ) objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Admin" ) ' objNet.AddWindowsPrinterConnection( "\\sun\Ky1800-DP" ) ' objNet.SetDefaultPrinter( "\\sun\HP2015n-Admin" ) WScript.Quit End If ' Create printers for computers in Room 102 cmp = InStr( 1, strComputerName, "ACW-102", 1) If cmp > 0 Then objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-102" ) objNet.SetDefaultPrinter( "\\Sun\HP1200-102" ) WScript.Quit End If ' Create printers for computers in Room 214 cmp = InStr( 1, strComputerName, "ACW-214", 1) If cmp > 0 Then objNet.RemovePrinterConnection ( "\\Sun\HP1200-102" ) , true, true objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-214" ) objNet.SetDefaultPrinter( "\\Sun\HP1200-214" ) WScript.Quit End If ' Create printers for computers in Room 215 cmp = InStr( 1, strComputerName, "ACW-215", 1) If cmp > 0 Then objNet.RemovePrinterConnection ( "\\Sun\HP1200-102" ) , true, true objNet.AddWindowsPrinterConnection( "\\Sun\HP2015n-215" ) objNet.SetDefaultPrinter( "\\Sun\HP2015n-215" ) WScript.Quit End If ' Create printers for computers in Library cmp = InStr( 1, strComputerName, "ACW-LIB", 1) If cmp > 0 Then objNet.RemovePrinterConnection ( "\\Sun\HP1200-102" ) , true, true objNet.AddWindowsPrinterConnection( "\\sun\HP2015n-Lib" ) objNet.SetDefaultPrinter( "\\sun\HP2015n-Lib" ) WScript.Quit End If ' Create printers for computers in Bookhire 'cmp = InStr( 1, strComputerName, "ACW-Bookhire", 1) 'If cmp > 0 Then ' objNet.AddWindowsPrinterConnection( "\\Sun\Ky1800-Lib" ) ' objNet.SetDefaultPrinter( "\\Sun\Ky1800-Lib" ) ' WScript.Quit 'End If ' Create printers for computers in Room 211 cmp = InStr( 1, strComputerName, "ACW-211", 1) If cmp > 0 Then objNet.AddWindowsPrinterConnection( "\\Sun\HP1200-214" ) objNet.SetDefaultPrinter( "\\Sun\HP1200-214" ) WScript.Quit End If End If
contink Posted June 19, 2009 Posted June 19, 2009 In terms of the script, this line stands out If objPrinter.Attributes And 64 Then No idea what the And 64 bit is all about. As for the rest, have you checked that the printer spooler on //SUN is running correctly... I've found that problems in that regard can give the impression that the script is at fault when it's actually the spooler. Also, have you changed anything in GPO to make script run asynchronously such that another script is using most of the timeout capacity, causing your script to stop early. Oooh, completely forgot... Have you got this in your code? On error resume next You may find that a missing printer is causing the script to terminate early.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now