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 ...
-
20th February 2008, 12:09 PM #1
- 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.
-
-
IDG Tech News
-
20th February 2008, 12:14 PM #2 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?
-
-
20th February 2008, 12:42 PM #3
- 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
-
-
20th February 2008, 12:54 PM #4
- Rep Power
- 12
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.
-
-
20th February 2008, 12:58 PM #5
- Rep Power
- 0
Thanks for the reply,
I will try that at lunch time, what is the force command in vbs?
Thanks
Martyn.
-
-
20th February 2008, 01:21 PM #6 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
-
-
20th February 2008, 01:22 PM #7 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
-
-
20th February 2008, 01:45 PM #8
- Rep Power
- 12
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
-
-
20th February 2008, 01:55 PM #9 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.
-
-
20th February 2008, 02:10 PM #10
- 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.
-
-
20th February 2008, 02:23 PM #11 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 to plexer from:
martyn (25th February 2008)
-
20th February 2008, 04:28 PM #12
- Rep Power
- 0
Cheers for that ! Will Try That One Now.
Martyn
-
-
20th February 2008, 05:05 PM #13
- Rep Power
- 0
Ok, there is an error on that one, WSHprinter variable not defined.
Martyn.
-
-
20th February 2008, 05:29 PM #14 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 to Iain from:
martyn (25th February 2008)
SHARE:
Similar Threads
-
Replies: 6
Last Post: 22nd November 2007, 04:03 PM
-
By wellwillthisnamedothen in forum How do you do....it?
Replies: 10
Last Post: 8th June 2007, 03:34 PM
-
By ajbritton in forum Scripts
Replies: 2
Last Post: 12th November 2006, 10:22 PM
-
By speckytecky in forum Networks
Replies: 1
Last Post: 31st May 2006, 06:44 PM
-
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
-
Forum Rules