martyn Posted February 20, 2008 Posted February 20, 2008 Hello all, I have an annoying printer script error, Here's the script applying to all authenticated users which correctly maps the three printers when the user logs in but always sets the default to Laser-Nul instead of the ICT1 Mono which it should be: 'Name : addprinter.vbs 'Author : Matt Davies 'Date : 22/03/2006 'Description : - Used to add printers for a user ' - Used inconjunction with group policy at Workstation level so it runs per room ' - Needs to be ran under "USER" Logon scripts Option Explicit On Error Resume Next Dim objNetwork 'declare the printer names - add as necessary Dim strUNCPrinter1 Dim strUNCPrinter2 Dim strUNCPrinter3 'set the UNC path to the printers you want mapped - add as necessary strUNCPrinter1 = "\\pc-bashful\PC-ICT1-MONO" strUNCPrinter2 = "\\pc-bashful\PC-ICT1-COLOUR" strUNCPrinter3 = "\\pc-bashful\LASER-NUL" Set objNetwork = CreateObject("WScript.Network") 'Add the printer to the computer - add as necessary objNetwork.AddWindowsPrinterConnection strUNCPrinter1 objNetwork.AddWindowsPrinterConnection strUNCPrinter2 objNetwork.AddWindowsPrinterConnection strUNCPrinter3 ' Here is where we set the default printer - change if necessary objNetwork.SetDefaultPrinter strUNCPrinter1 'End the script Wscript.Quit It is very frustrating, anyone got any ideas or know if there is a way to force the correct default through vbs. Many thanks in advance Martyn.
contink Posted February 20, 2008 Posted February 20, 2008 stupid question but is the default printer actually online, working and available (permissions) to the users logging in? Also, is the default printer directly connected to or shared from the machine you're trying to login with?
martyn Posted February 20, 2008 Author Posted February 20, 2008 Thanks for the reply: Yes the printer is alive and kicking and will print, permissions are set so that everyone can print, The printer is shared from a server (pc-bashful) and the script is applied when a user logs into a machine in that particular room. Thanks Martyn
pallen Posted February 20, 2008 Posted February 20, 2008 May be being a bit thick here, but cant you just move the default printer to the last one thats mapped? I have ours setup so that the default is the last one listed and I force the default printer in the script. That way if the script fails at any point, it has 2 chances to set the default printer correctly.
martyn Posted February 20, 2008 Author Posted February 20, 2008 Thanks for the reply, I will try that at lunch time, what is the force command in vbs? Thanks Martyn.
plexer Posted February 20, 2008 Posted February 20, 2008 Think he means change the order in which you allocate them in your script so that the one you want to be default is last. I use a similar script but also specify the printer driver to use. Ben
plexer Posted February 20, 2008 Posted February 20, 2008 Hmm just looked it up and specifying the drive is only needed for 9x/me which I don't have. Makes it simpler then. Ben
pallen Posted February 20, 2008 Posted February 20, 2008 Yes, I mean put the printer (which you want as default) as the last one that is mapped. It is then set as the default. Sorry if it was a bit vague, cant focus my eyes this morning
srochford Posted February 20, 2008 Posted February 20, 2008 Try commenting out the "on error resume next" to see if some error (which I can't see!) is happening to prevent the code getting to that last line. Also, run the script with the debugger to see if that gives you any other useful info.
martyn Posted February 20, 2008 Author Posted February 20, 2008 Thanks again for all the replies, ok now trying a slightly altered script, See below, If i comment out (on error resume next) I get a overlapping IO script host error on line 18: "" objNetwork.AddWindowsPrinterConnection strUNCPrinter "" Then it only maps 'laser nul' not the other two, but if the 'on error resume next' is there it maps all three but sets the wrong default. Eek !!! Cant kids use a pen and paper ! Thanks again. ' SetDefaultPrinter.vbs - Windows logon script example ' PrintersDefault.vbs - Set the default printer ' VBScript - to map a network printer ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 1.4 - April 24th 2005 ' -----------------------------------------------------------------' Option Explicit Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2 strUNCPrinter = "\\pc-bashful\LASER-NUL" strUNCPrinter1 = "\\pc-bashful\PC-ICT1-COLOUR" strUNCPrinter2 = "\\pc-bashful\PC-ICT1-MONO" Set objNetwork = CreateObject("WScript.Network") objNetwork.AddWindowsPrinterConnection strUNCPrinter objNetwork.AddWindowsPrinterConnection strUNCPrinter1 objNetwork.AddWindowsPrinterConnection strUNCPrinter2 ' Here is where we set the default printer to strUNCPrinter objNetwork.SetDefaultPrinter strUNCPrinter2 WScript.Quit ' End of Guy's Windows logon example VBScript.
plexer Posted February 20, 2008 Posted February 20, 2008 Try this: Option Explicit Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2 strUNCPrinter = "\\pc-bashful\LASER-NUL" strUNCPrinter1 = "\\pc-bashful\PC-ICT1-COLOUR" strUNCPrinter2 = "\\pc-bashful\PC-ICT1-MONO" Set objNetwork = CreateObject("WScript.Network") 'Remove ALL old printers 'Enumerate all printers first, after that you can select the printers you want by performing some string checks Set WSHPrinters = objNetwork.EnumPrinterConnections For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2 'To remove only networked printers use this If Statement If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True End If 'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above 'objNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True Next 'end delete existing printers objNetwork.AddWindowsPrinterConnection strUNCPrinter objNetwork.AddWindowsPrinterConnection strUNCPrinter1 objNetwork.AddWindowsPrinterConnection strUNCPrinter2 ' Here is where we set the default printer to strUNCPrinter objNetwork.SetDefaultPrinter strUNCPrinter2 WScript.Quit ' End of Guy's Windows logon example VBScript. Should delete existing printers then map new ones. Ben 1
martyn Posted February 20, 2008 Author Posted February 20, 2008 Cheers for that ! Will Try That One Now. Martyn
martyn Posted February 20, 2008 Author Posted February 20, 2008 Ok, there is an error on that one, WSHprinter variable not defined. Martyn.
Iain Posted February 20, 2008 Posted February 20, 2008 If you declare the WSHPrinters variable using the dim statement or comment out the Option Explicit statement, that sould get rid of the error. Iain. 1
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