karldenton Posted April 11, 2008 Posted April 11, 2008 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
Sirbendy Posted April 11, 2008 Posted April 11, 2008 We tend to do ours with a batchfile that runs at user login using con2prt to map..
gshaw Posted April 11, 2008 Posted April 11, 2008 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.
srochford Posted April 11, 2008 Posted April 11, 2008 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 :-)
karldenton Posted April 14, 2008 Author Posted April 14, 2008 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
gshaw Posted April 14, 2008 Posted April 14, 2008 (edited) 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 Edited April 14, 2008 by gshaw
Ric_ Posted April 14, 2008 Posted April 14, 2008 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.
karldenton Posted April 14, 2008 Author Posted April 14, 2008 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\LibraryPrinter\liblogon.bat The script executes: "cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinter\libdefault.vbs". Done a gpupdate /force but still does't seem to work. Any ideas. Thanks again
Geoff Posted April 14, 2008 Posted April 14, 2008 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
notalot Posted April 14, 2008 Posted April 14, 2008 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
plexer Posted April 14, 2008 Posted April 14, 2008 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
Ric_ Posted April 14, 2008 Posted April 14, 2008 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\LibraryPrinter\liblogon.bat The script executes: "cscript.exe \\2003server\SharedArea\ITTechnician\LibraryPrinter\libdefault.vbs". Instead of having the batch file, just call the VBScript directly from the GPO.
busby Posted March 23, 2010 Posted March 23, 2010 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
Stuart_C Posted March 23, 2010 Posted March 23, 2010 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"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now