+ Post New Thread
Results 1 to 14 of 14
Windows Thread, Default Printer Batch File in Technical; Hello, I would like a batch file to rung at system startup/userlogon to set the default printer for all users. ...
  1. #1

    Join Date
    Apr 2007
    Location
    Ramsbottom, Bury, Lancs
    Posts
    581
    Thank Post
    11
    Thanked 5 Times in 5 Posts
    Rep Power
    20

    Default Printer Batch File

    Hello,
    I would like a batch file to rung at system startup/userlogon to set the default printer for all users. I set it as administator but it then doesn't change for users. I can't really put it in the logon.bat as its only needed for one room and the other rooms have a different default.
    Thanks

  2. #2
    Sirbendy's Avatar
    Join Date
    Nov 2005
    Posts
    2,305
    Thank Post
    8
    Thanked 205 Times in 155 Posts
    Rep Power
    111
    We tend to do ours with a batchfile that runs at user login using con2prt to map..

  3. #3
    gshaw's Avatar
    Join Date
    Sep 2007
    Location
    Essex
    Posts
    2,726
    Thank Post
    176
    Thanked 229 Times in 211 Posts
    Rep Power
    69
    How about a .vbs script?


    ' VBScript.
    Set net = WScript.CreateObject("wscript.network")

    net.AddWindowsPrinterConnection "\\server\printer"
    net.AddWindowsPrinterConnection "\\server\printer2"

    net.SetDefaultPrinter "\\server\printer"


    I got fed up of having different scripts for each OU so made a new one from some examples on the web that maps a few general printers, checks the OU of the Computer then maps any specific ones after that. It also looks to see if the current user is a member of a colour printer group, if so they get it mapped automatically Hopefully should be rolling that out in the summer on the top level policy so when staff move offices their default printer changes as well.

  4. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,159
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    125
    Quote Originally Posted by karldenton View Post
    Hello,
    I would like a batch file to rung at system startup/userlogon to set the default printer for all users. I set it as administator but it then doesn't change for users. I can't really put it in the logon.bat as its only needed for one room and the other rooms have a different default.
    Thanks
    You have to do this as a user script because (as you've found!) things like default printer are user specific.

    There's a million (!) ways to do it but basically, you need to determine which room you're in and then set the default appropriately. Assuming you put computers into specific OUs based on rooms then your script just needs to find the OU and then map accordingly - there are loads of examples here about how to do this.

    The nice, new, sexy way to do this is with group policy preferences - we're still rolling out the extension to our workstations so I haven't yet tried this but I think it has the potential to make life much easier :-)

  5. #5

    Join Date
    Apr 2007
    Location
    Ramsbottom, Bury, Lancs
    Posts
    581
    Thank Post
    11
    Thanked 5 Times in 5 Posts
    Rep Power
    20
    Thanks for the replys.
    I've got a batch file, which works:

    ' Option Explicit

    Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2


    strUNCPrinter = "\\2003server\libraryb1430"

    Set objNetwork = CreateObject("WScript.Network")

    Set WSHPrinters = objNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2

    'objNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    Next
    'end delete existing printers

    objNetwork.AddWindowsPrinterConnection strUNCPrinter


    objNetwork.SetDefaultPrinter strUNCPrinter

    WScript.Quit


    Is it possible to asign this to a computer OU rather than user?

    Thanks

    Karl

  6. #6
    gshaw's Avatar
    Join Date
    Sep 2007
    Location
    Essex
    Posts
    2,726
    Thank Post
    176
    Thanked 229 Times in 211 Posts
    Rep Power
    69
    We used to have a script that had that loop counter in there but it never seemed to work right, if you want to delete all network printers before mapping try this...

    '****************************
    'Deletes old network printers
    '****************************

    On error Resume Next
    Dim cNetCommands, vPrinterName, vPrinterPath
    Set cNetCommands = WScript.CreateObject("WScript.Network")
    Set vPrinterPath = cNetCommands.EnumPrinterConnections
    For Each vPrinterName in vPrinterPath
    cNetCommands.RemovePrinterConnection(vPrinterName)
    Next
    Wscript.Quit


    Seems to work a lot more reliably for me

    As for assigning to computers this link may prove useful

    Logon Script Example Assign Printer - RUNDLL32 PRINTUI.DLL
    Last edited by gshaw; 14th April 2008 at 12:42 PM.

  7. #7

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,601
    Thank Post
    110
    Thanked 771 Times in 599 Posts
    Rep Power
    183
    As others have basically said... there's no point re-inventing the wheel. Check out Scripting Printer Addition Based on Location - EduGeek.net Wiki and if others have anything to add please do add it to the wiki.

  8. #8

    Join Date
    Apr 2007
    Location
    Ramsbottom, Bury, Lancs
    Posts
    581
    Thank Post
    11
    Thanked 5 Times in 5 Posts
    Rep Power
    20
    OK guys, thanks foe the help.
    Like i said, i have this vbs file which works fine when you run it as any user. I have put it in a shared location on the network. In gp, user config, windows settings, scripts, logon i have put a path to a logon script, which is :

    \\2003server\SharedArea\ITTechnician\LibraryPrinte r\liblogon.bat

    The script executes:

    "cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinte r\libdefault.vbs".

    Done a gpupdate /force but still does't seem to work.

    Any ideas.

    Thanks again

  9. #9

    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
    Quote Originally Posted by Ric_ View Post
    As others have basically said... there's no point re-inventing the wheel. Check out Scripting Printer Addition Based on Location - EduGeek.net Wiki and if others have anything to add please do add it to the wiki.
    Hmm, I should probably add my enhancements

  10. #10

    Join Date
    Dec 2007
    Location
    Nottinghamshire
    Posts
    206
    Thank Post
    62
    Thanked 26 Times in 22 Posts
    Rep Power
    19
    we put a shortcut in all users > startup from a shair on the server that let students and staff have read access, works a treat

  11. #11

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,689
    Thank Post
    756
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438
    karl: It appears that you have a vbscript allready and not a batch script.

    gshaw: Doesn't your script remove ALL printers and not just network ones?

    Ben

  12. #12

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    Boston, MA
    Posts
    7,601
    Thank Post
    110
    Thanked 771 Times in 599 Posts
    Rep Power
    183
    Quote Originally Posted by karldenton View Post
    OK guys, thanks foe the help.
    Like i said, i have this vbs file which works fine when you run it as any user. I have put it in a shared location on the network. In gp, user config, windows settings, scripts, logon i have put a path to a logon script, which is :

    \\2003server\SharedArea\ITTechnician\LibraryPrinte r\liblogon.bat

    The script executes:

    "cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinte r\libdefault.vbs".
    Instead of having the batch file, just call the VBScript directly from the GPO.

  13. #13
    busby's Avatar
    Join Date
    Dec 2009
    Location
    manchester
    Posts
    149
    Thank Post
    38
    Thanked 15 Times in 13 Posts
    Rep Power
    13
    We got printers installed on each machine all printing to the same 2 printers one colour and one mono
    i wanna change the default with out going to each machine i can do it locally or creating a startup bat file using defprint but i wanna do it like this because im lazy lol

    defprint \\suite04 /d "IP_192.168.1.188"
    defprint \\suite05 /d "IP_192.168.1.188"

    but i cant seem to find the right switches any ideas? i dont really want to use a script or something that runs at starts up but ran once and thats it.

    thanks
    chris

  14. #14

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,679
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    46
    The below works fine for me. If I'm honest a friend sent it to me... But I'm not! It's MINE! ALL MY OWN WORK!!!!

    This also works to apply any users settings to a computer regardless of who logs into it.


    For script to run on computers use Loopback processing in Merge Mode

    That would allow you to apply a script to a Computer Account but using the User section of the policy.

    To set it up what you need to do is:

    1. Create a Group Policy with the Loopback Policy enabled:

    Computer Configuration --> Administrative Templates --> System --> Group Policy

    User Group Policy loopback processing mode: Enabled & Merge

    2. Create a Group Policy attached to the OU containing the computer account with the script in the:

    User Configuration --> Windows Settings --> Scripts Logon --> printers.vbs.

    The Replace operation stops all other User based policies applying there and only uses those that would apply to the Computer OU.

    The Merge operation uses the normal User based policies as well, but any policies set on the Computer OU take precedence.

    Script for automated mapping of printer according to room number:

    rem ** Next line must not be deleted **
    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
    rem ** Setup new printer connection **
    WshNetwork.AddWindowsPrinterConnection "\\server\HP"
    rem ** Setup default printer **
    WshNetwork.SetDefaultPrinter "\\server\HP"



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 13
    Last Post: 20th February 2008, 05:29 PM
  2. Pass £ in batch file
    By meastaugh1 in forum Windows
    Replies: 2
    Last Post: 17th January 2008, 09:02 PM
  3. Rename a PC from a batch file - Any ideas?
    By MrLudwig in forum Windows
    Replies: 13
    Last Post: 8th December 2007, 03:40 AM
  4. batch file to shutdown PCs
    By macca in forum Windows
    Replies: 5
    Last Post: 3rd May 2007, 10:20 AM
  5. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 08:48 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
  •