Jump to content

Printer Logon Script Not Setting Correct Default Printer


Recommended Posts

Posted

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.

Posted

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?

Posted

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 :)

Posted
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.
Posted

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

Posted
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
Posted
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.
Posted

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.

Posted

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

  • Thanks 1
Posted

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.

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...