Site Maintenance this evening The site will be offline for hosting changes. Time TBC

+ Post New Thread
Results 1 to 14 of 14
Scripts Thread, Printer Logon Script Not Setting Correct Default Printer in Coding and Web Development; Hello all, I have an annoying printer script error, Here's the script applying to all authenticated users which correctly maps ...
  1. #1

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Printer Logon Script Not Setting Correct Default Printer

    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.

  2. #2
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118
    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?

  3. #3

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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

  4. #4

    Join Date
    Mar 2007
    Posts
    307
    Thank Post
    3
    Thanked 9 Times in 8 Posts
    Rep Power
    17
    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.

  5. #5

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for the reply,

    I will try that at lunch time, what is the force command in vbs?


    Thanks


    Martyn.

  6. #6

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  7. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  8. #8

    Join Date
    Mar 2007
    Posts
    307
    Thank Post
    3
    Thanked 9 Times in 8 Posts
    Rep Power
    17
    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 :P

  9. #9

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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.

  10. #10

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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.

  11. #11

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  12. Thanks to plexer from:

    martyn (25th February 2008)

  13. #12

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Cheers for that ! Will Try That One Now.


    Martyn

  14. #13

    Join Date
    Feb 2008
    Location
    Swansea
    Posts
    10
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Ok, there is an error on that one, WSHprinter variable not defined.

    Martyn.

  15. #14
    Iain's Avatar
    Join Date
    Oct 2006
    Location
    Warwickshire
    Posts
    187
    Thank Post
    28
    Thanked 93 Times in 53 Posts
    Rep Power
    31
    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.

  16. Thanks to Iain from:

    martyn (25th February 2008)

SHARE:
+ Post New Thread

Similar Threads

  1. logon script for printer
    By ozzy in forum Scripts
    Replies: 6
    Last Post: 22nd November 2007, 03:03 PM
  2. setting a default printer for all users
    By wellwillthisnamedothen in forum How do you do....it?
    Replies: 10
    Last Post: 8th June 2007, 03:34 PM
  3. Cunning 'default printer' script
    By ajbritton in forum Scripts
    Replies: 2
    Last Post: 12th November 2006, 09:22 PM
  4. Change network printer default setting
    By speckytecky in forum Wireless Networks
    Replies: 1
    Last Post: 31st May 2006, 06:44 PM
  5. Setting a permanent default printer.
    By ninjabeaver in forum Windows
    Replies: 25
    Last Post: 23rd August 2005, 05:55 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •