+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
Windows Thread, Setting a permanent default printer. in Technical; Hi, OK, this one has been bugging me for a while but been on the back burner. Through the school ...
  1. #1
    ninjabeaver's Avatar
    Join Date
    Jun 2005
    Location
    Norfolk
    Posts
    1,090
    Thank Post
    183
    Thanked 100 Times in 88 Posts
    Rep Power
    47

    Setting a permanent default printer.

    Hi,

    OK, this one has been bugging me for a while but been on the back burner. Through the school network we have installed the networked printers through a simple script inside a batch file. That works great, but........... for example we have a PC in the staff room that also has a colour inkjet next to it. I would like this networked colour inkjet to be the default printer, but it always defaults to the black and white one next door. Anyone got any ideas how to set this to use the colour inkjet as default? I also have similar things happening around the school.
    Thanks

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    123
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Setting a permanent default printer.

    Just use VB something like

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.SetDefaultPrinter "\\thiscomputer\colourpinter"

  3. #3

    Join Date
    Jun 2005
    Location
    Bristol
    Posts
    51
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Setting a permanent default printer.

    edit your printer script (Presuming your using VBScript)

    Add "SleepTime=15" - without quotes to the top of your script

    put the following in at the end.

    WScript.Sleep SleepTime*1000
    WshNetwork.SetDefaultPrinter "\\[ServerName]\StaffRoom-Colour"

    The reason your add a sleep time is so that the machine has enough chance to install the printer then set it, some machine are so quick at running the script it finishes before the printers are added and the default doesn't set.

    Our full script for staff room:

    rem ** Next line must not be deleted **
    SleepTime=15
    Set WshNetwork = CreateObject("WScript.Network")

    rem ** This will delete existing printers **
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
    For i = 1 to oPrinters.Count - 1 Step 2
    WshNetwork.RemovePrinterConnection oPrinters.Item(i)
    Next

    WshNetwork.AddWindowsPrinterConnection "\\[ServerName]\StaffRoom-Colour"

    rem ** Set Default Printer **
    WScript.Sleep SleepTime*1000
    WshNetwork.SetDefaultPrinter "\\[ServerName]\StaffRoom-Laser"

  4. #4
    ninjabeaver's Avatar
    Join Date
    Jun 2005
    Location
    Norfolk
    Posts
    1,090
    Thank Post
    183
    Thanked 100 Times in 88 Posts
    Rep Power
    47

    Re: Setting a permanent default printer.

    OK, perhaps 'script' was a bit too strong for what this is.

    I'm running a batch file with items like this in it.

    'rundll32 printui.dll,PrintUIEntry /ga /c\\RM54-01 /n\\PHServer3\BWRoom53'

    with the PC number (RM54-01, RM54-02) etc going up until all the PC's in that room are covered.

    This is run once when the room has been re-imaged or a single PC is repaired, re-imaged etc.

    Now, if that printer is the only one in there then fine but if I want to add another printer but leave the first one as default it keeps reverting to the last one installed.

    I've never done VB Scripting either, and websites I can look at to workout how to do the above??

    Thanks.

  5. #5
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    123
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Setting a permanent default printer.

    You basically want something like this:

    Code:
    'Server Definitions
    Const File_Server = "\\FMDC1\"
    Const Print_Server = "\\FMDC2\"
    
    'Printer definitions
    Const Room22_Mono = "Room22MonoPrinter"
    Const Room22_Colour = "Room22ColourPrinter"
    Const Room25_Mono = "Room25MonoPrinter"
    Const Room25_Colour = "Room25Colour"
    Const Room30_Mono = "Room30MonoPrinter"
    Const Room30_Colour = "Room30ColourPrinter"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    StrComputerName = Left(LCase(WshNetwork.ComputerName),4)
    
    
    StrComputerName = Left(LCase(WshNetwork.ComputerName),4)
    
    ' Delete existing network Printers
    For i = 0 to ObjPrinters.Count - 1 Step 2
                On Error Resume Next
    		if Left(ObjPrinters.Item(i), 3) <> "lpt" And Left(ObjPrinters.Item(i), 3) <> "usb" then
                 	WshNetwork.RemovePrinterConnection ObjPrinters.Item(i+1), true, true
                else WScript.Echo "No network printers found"
                end if
    Next
    
    ' Add Network Printers according to location
    Select Case (Left(StrComputerName, 4))
    	Case "it22"
    		WshNetwork.AddWindowsPrinterConnection Print_server & Room22_Mono
    		WshNetwork.AddWindowsPrinterConnection Print_server & Room22_Colour
    		WshNetwork.SetDefaultPrinter Print_server & Room22_Mono
    	Case Else
    		' WScript.Echo "No default printers added"
    End Select 'End printer Case Statements
    
    
    '************************* End Of Printer Setup *************************
    This will remove all printers apart from local ones and add a printer according to teh computer anme. All the definitions are at the top in the constants.

    There are may VB script resources out there the Microsoft Script Centre is a good place to start.

  6. #6
    tarquel's Avatar
    Join Date
    Jun 2005
    Location
    Powys, Mid-Wales, UK
    Posts
    1,740
    Thank Post
    13
    Thanked 45 Times in 35 Posts
    Rep Power
    30

    Re: Setting a permanent default printer.

    But if thats to confusing for you (as you havent done VB scripting before), you could always try kixtart script files which - to me, are a bit more easy to understand I find.

    Here's my current one (its by no means finished ppl so no flaming please):
    Code:
    DelPrinterConnection ("\\SERVERNAME\HP LaserJet 1300n")
    DelPrinterConnection ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6")
    DelPrinterConnection ("\\SERVERNAME\hp LaserJet 1320")
    
    set computer="@wksta"
    $room=SubStr(@wksta,1,2)
    $client=SubStr(%clientname%,3,2)
    Select
      Case ($room="07") 
         AddPrinterConnection ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6")
         AddPrinterConnection ("\\SERVERNAME\hp LaserJet 1320")
         SetDefaultPrinter ("\\SERVERNAME\HP LaserJet 1200 Series PCL 6")
    EndSelect
    
    Select
      Case ($room="HU") 
         AddPrinterConnection ("\\SERVERNAME\HP LaserJet 1300n")
         SetDefaultPrinter ("\\SERVERNAME\hp LaserJet 1300n")
    EndSelect
    (this file for me is called printer.kix)

    I have this in the 'netlogon' share of the server along with the kix32.exe and you just need to change:

    - the servername to what server is the print server
    - the room & client variable information to however you name/order the computers in your 'computername'
    - Change the printer(s) names and/or location to whatever their sharename (or full name is too)
    - You can add more sections and printers easily and its amazing how quick it works - even when there is a class of pupils logging on.

    You add it to your logon.bat (if you use one) as:

    Code:
    echo - Mounting printers for this room or computer...please wait...
    echo.
    
    \\SERVERNAME\NETLOGON\kix32.exe \\SERVERNAME\NETLOGON\printer.kix
    (where servername is you DC most likely)

    search google for kixtart and you should find the site, although if ya want, I can always send you the file(s).

    A few of us (that I chat to) in powys use this system and it works great

    Cheers, and good luck.
    Nath

  7. Thanks to tarquel from:

    newpersn (27th August 2014)

  8. #7
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,987
    Thank Post
    271
    Thanked 52 Times in 46 Posts
    Blog Entries
    2
    Rep Power
    48

    Re: Setting a permanent default printer.

    looks familiar Nath hehe!

    [The client name is actually for my citrix clients so I don't see you need that bit]

  9. #8

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227

    Re: Setting a permanent default printer.

    Ric has a good printer vbs script. Any chance of posting it Ric? or shall I post my multilated version of it?

  10. #9
    tarquel's Avatar
    Join Date
    Jun 2005
    Location
    Powys, Mid-Wales, UK
    Posts
    1,740
    Thank Post
    13
    Thanked 45 Times in 35 Posts
    Rep Power
    30

    Re: Setting a permanent default printer.

    Oooops lol

    [yes - I've only learnt about this from mark and another bloke in powys btw]

    I thought it was for specific computer identifying i.e. 20 pc's in a room. I want one of those PC's to map a printer but not the others. Thought I could use both the Room and client variable to specify this sorta thing

    I would also like to add some way of basing it on user too - I'm sure it is fairly obvious (i.e. different scripts for different users etc but just simply right now...).

    Cheers
    Nath

    PS @ mark: Wynn just left a message of my phone wondering why he couldnt connect to the admin server - to quote "Can you think of a reason why that is?" ....lol I can... Its because the server isn't on lol

  11. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    123
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Setting a permanent default printer.

    Looking at that Kix script I wouldnt say VB script syntax was any more difficult than kix. Maybe mine just looks a little complicated because I used constants for the printers name in the add printer commands?

  12. #11
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,987
    Thank Post
    271
    Thanked 52 Times in 46 Posts
    Blog Entries
    2
    Rep Power
    48

    Re: Setting a permanent default printer.

    Quote Originally Posted by tarquel
    I would also like to add some way of basing it on user too - I'm sure it is fairly obvious (i.e. different scripts for different users etc but just simply right now...).
    I'm sure that'd be easy with kix - just find the user call.

    [LOL @ Wynn ]

  13. #12

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,597
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183

    Re: Setting a permanent default printer.

    Here is the hallowed printer script. This copy may be slightly out of date.

    You will notice that it refers to a computer called SVRTS1 - this is a citrix server and that particular line moves the terminal's name into the computername variable so that the printer is mapped correctly.

    You may play about with it but don't slag it off too much - I knwo that it should be better documented and should probably involve some better error handling.

    You may also add single lines of the form

    Code:
    if (computerName = "BillsPC") then WshNetwork.AddWindowsPrinterConnection "\\BensServer\a_network_printer"
    Add these at the end for any unusual printer mappings.
    Attached Files Attached Files

  14. #13

    Join Date
    Jun 2005
    Location
    Bristol
    Posts
    51
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Setting a permanent default printer.

    Quote Originally Posted by Ric_
    Here is the hallowed printer script. This copy may be slightly out of date.

    You will notice that it refers to a computer called SVRTS1 - this is a citrix server and that particular line moves the terminal's name into the computername variable so that the printer is mapped correctly.

    You may play about with it but don't slag it off too much - I knwo that it should be better documented and should probably involve some better error handling.

    You may also add single lines of the form

    Code:
    if (computerName = "BillsPC") then WshNetwork.AddWindowsPrinterConnection "\\BensServer\a_network_printer"
    Add these at the end for any unusual printer mappings.
    Good Work! - we currently have seperate vbs files for each room but will now look at one file.

  15. #14
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    123
    Thanked 286 Times in 263 Posts
    Rep Power
    108

    Re: Setting a permanent default printer.

    You may want to use a case statement it will be neater.

  16. #15
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    31

    Re: Setting a permanent default printer.

    to make the printer a default printer add the "default" work!! i.e.

    Code:
    Dim oNetwork, sPrintPath
    Set oNetwork = CreateObject("WScript.Network")
    
    	sPrintPath ="\\10.102.28.7\Science"
    	oNetwork.AddWindowsPrinterConnection sPrintPath
    	oNetwork.SetDefaultPrinter sPrintPath
    	
    
    WScript.Quit



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Default Profiles - setting user directories
    By speckytecky in forum Windows
    Replies: 0
    Last Post: 22nd June 2007, 08:52 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, 04:34 PM
  3. Cunning 'default printer' script
    By ajbritton in forum Scripts
    Replies: 2
    Last Post: 12th November 2006, 10:22 PM
  4. Change network printer default setting
    By speckytecky in forum Wireless Networks
    Replies: 1
    Last Post: 31st May 2006, 07:44 PM
  5. Replies: 17
    Last Post: 16th September 2005, 09:07 AM

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
  •